All pastes #465171 Raw Edit

Mine

public text v1 · immutable
#465171 ·published 2007-04-29 23:48 UTC
rendered paste body
        public static Object FetchFromCache(string hash, Type type)
        {
            try {
                MemcachedClient mc = new MemcachedClient();
                string data = mc.Get(hash);

                if (data == null || data == "")
                    return null;

                XmlSerializer xs = new XmlSerializer(type);
                MemoryStream ms = new MemoryStream(StrToByteArray(data));
                ms.Seek(0, SeekOrigin.Begin);

                return xs.Deserialize(ms);
            } catch {
                CoreData.QualityStandalone.simple_logger("MCH", "Cache: could not fetch cache object " + hash + " of type " + type.ToString());
                return null;
            }
        }
        public static void SaveToCache(Object inobj, string hash, Type type)
        {
            try
            {
                XmlSerializer xs = new XmlSerializer(type);
                MemoryStream ms = new MemoryStream();

                // serialize it
                xs.Serialize(ms, inobj);

                // save the data
                ms.Seek(0, SeekOrigin.Begin);
                StreamReader sr = new StreamReader(ms);
                string data = sr.ReadToEnd();
                MemcachedClient mc = new MemcachedClient();
                mc.Set(hash, data);

                return;
            }
            catch
            {
                CoreData.QualityStandalone.simple_logger("MCH", "Cache: could not save to cache " + hash + " of type " + type.ToString());
            }
        }