Ejemplo n.º 1
0
        public int FindCount(Type t, String condition)
        {
            if (CacheTime.isCountUpdate(t, condition))
            {
                return(-1);
            }
            String key = CacheKey.getCountKey(t, condition);
            Object obj = getFromApplication(key);

            return(obj == null ? -1 : (int)obj);
        }
Ejemplo n.º 2
0
        public void Add(IEntity obj)
        {
            if (obj == null)
            {
                return;
            }

            String key = CacheKey.getObject(obj.GetType(), obj.Id);

            addToContext(key, obj);
            CacheTime.updateObject(obj);   // 加入缓存的时候,设置最新 timestamp
        }
Ejemplo n.º 3
0
 private void addList(String key, IList objList)
 {
     if (objList == null)
     {
         return;
     }
     addToContext(key, objList);
     foreach (IEntity obj in objList)
     {
         ContextCache.Put(CacheKey.getObject(obj.GetType(), obj.Id), obj);
     }
     CacheTime.updateList(key);
 }
Ejemplo n.º 4
0
        public IEntity FindOne(Type t, int id)
        {
            String key = CacheKey.getObject(t, id);

            IEntity result = getFromApplication(key) as IEntity;

            if (result != null)
            {
                if (CacheTime.isObjectUpdated(result))
                {
                    return(null);                                     // 检查是否更新
                }
                logger.Debug("APP_cache_get=>" + key);

                return(result);
            }

            return(null);
        }
Ejemplo n.º 5
0
        //-----------------------------------------------------------

        internal IList getListFromCache(String queryKey, Type t)
        {
            if (CacheTime.isListUpdate(queryKey, t))
            {
                return(null);
            }

            List <int> ids = appCache.Get(queryKey) as List <int>;

            if (ids == null)
            {
                return(null);
            }

            IList result = new ArrayList();

            foreach (int id in ids)
            {
                IEntity obj = this.findOnePrivate(t, id);

                if (obj == null)
                {
                    return(null);
                }

                if (CacheTime.isObjectUpdated(obj))
                {
                    return(null);                                  // 如果有任何一个对象更新过,则缓存失效
                }
                // 检查实体属性
                renewEntityPropertyValue(obj);

                result.Add(obj);
            }


            logger.Debug("APP_cache_get=>" + queryKey);
            return(result);
        }
Ejemplo n.º 6
0
        private static void addList(String key, IList objList)
        {
            if (objList == null)
            {
                return;
            }

            foreach (IEntity obj in objList)
            {
                addToApplication(CacheKey.getObject(obj.GetType(), obj.Id), obj);
                CacheTime.updateObject(obj);   // 加入缓存的时候,设置最新 timestamp
            }

            List <int> ids = new List <int>();

            foreach (IEntity obj in objList)
            {
                ids.Add(obj.Id);
            }
            addToApplication(key, ids);
            CacheTime.updateList(key);
        }
Ejemplo n.º 7
0
 public void Clear()
 {
     appCache.Clear();
     CacheTime.Clear();
 }
Ejemplo n.º 8
0
 public void Delete(Type t, int id)
 {
     appCache.Remove(CacheKey.getObject(t.FullName, id));
     logger.Debug("Delete=>" + t.FullName + id);
     CacheTime.updateTable(t);
 }