Exemplo n.º 1
0
        public IEntitySlim GetEntity(Guid id)
        {
            if (!_cacheEnabled)
            {
                return(entityService.Get(id));
            }

            // double cache lookup, we only store id's in the key cache,
            // that way we are not double storing all the entityIds in memory.

            IEntitySlim entity = null;
            var         intId  = keyCache.GetCacheItem(id.ToString(), () =>
            {
                entity = entityService.Get(id);
                if (entity != null)
                {
                    return(entity.Id);
                }

                return(0);
            });

            if (intId != 0)
            {
                return(cache.GetCacheItem(intId.ToString(), () =>
                {
                    if (entity != null)
                    {
                        return entity;
                    }
                    return entityService.Get(intId);
                }));
            }
            else
            {
                keyCache.ClearByKey(id.ToString());
                return(null);
            }
        }
Exemplo n.º 2
0
        public IEntitySlim GetEntity(int id)
        {
            if (!_cacheEnabled)
            {
                return(entityService.Get(id));
            }

            return(cache.GetCacheItem(id.ToString(), () =>
            {
                return entityService.Get(id);
            }));
        }