Exemplo n.º 1
0
        public virtual CachedEntity Put(IEntity entity, bool storeState)
        {
            ConcurrentDictionary <string, CachedEntity> classCache = cachedObjects.GetOrAdd(entity.GetType(), new ConcurrentDictionary <string, CachedEntity>()) as ConcurrentDictionary <string, CachedEntity>;
            CachedEntity cachedObject = new CachedEntity(entity, storeState);

            classCache.AddOrUpdate(entity.Id, cachedObject, (id, cacheObject) => cachedObject);
            return(cachedObject);
        }
Exemplo n.º 2
0
        public virtual object FindInCache(Type entityClass, string id)
        {
            CachedEntity cachedObject = null;

            cachedObjects.TryGetValue(entityClass, out IDictionary <string, CachedEntity> classCache);
            if (classCache == null)
            {
                classCache = FindClassCacheByCheckingSubclasses(entityClass);
            }

            if (classCache != null)
            {
                classCache.TryGetValue(id, out cachedObject);
            }

            if (cachedObject != null)
            {
                return(cachedObject.Entity);
            }

            return(null);
        }