Exemplo n.º 1
0
        public void InvalidateSets(IEnumerable <string> entitySets, DbInfo db)
        {
            if (entitySets == null)
            {
                throw new ArgumentNullException("entitySets");
            }

            lock (_cache)
            {
                var itemsToInvalidate = new HashSet <string>();

                foreach (var entitySet in entitySets)
                {
                    HashSet <string> keys;

                    if (_entitySetToKey.TryGetValue(entitySet, out keys))
                    {
                        itemsToInvalidate.UnionWith(keys);

                        _entitySetToKey.Remove(entitySet);
                    }
                }

                foreach (var key in itemsToInvalidate)
                {
                    InvalidateItem(key, db);
                }
            }
        }
Exemplo n.º 2
0
        public bool GetItem(string key, out object value, DbInfo db)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            value = null;

            lock (_cache)
            {
                var now = DateTimeOffset.Now;

                CacheEntry entry;
                if (_cache.TryGetValue(key, out entry))
                {
                    if (EntryExpired(entry, now))
                    {
                        InvalidateItem(key, db);
                    }
                    else
                    {
                        entry.LastAccess = now;
                        value            = entry.Value;
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        public void InvalidateItem(string key, DbInfo db)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            lock (_cache)
            {
                CacheEntry entry;

                if (_cache.TryGetValue(key, out entry))
                {
                    _cache.Remove(key);

                    foreach (var set in entry.EntitySets)
                    {
                        HashSet <string> keys;
                        if (_entitySetToKey.TryGetValue(set, out keys))
                        {
                            keys.Remove(key);
                        }
                    }
                }
            }
        }
 public virtual void PutItem(DbTransaction transaction, string key, object value,
                             IEnumerable <string> dependentEntitySets, TimeSpan slidingExpiration,
                             DateTimeOffset absoluteExpiration, DbInfo db)
 {
     if (transaction == null)
     {
         _cache.PutItem(key, value, dependentEntitySets, slidingExpiration, absoluteExpiration, db);
     }
 }
        public virtual bool GetItem(DbTransaction transaction, string key, DbInfo db, out object value)
        {
            if (transaction == null)
            {
                return(_cache.GetItem(key, out value, db));
            }

            value = null;

            return(false);
        }
Exemplo n.º 6
0
        public void InvalidateSets(IEnumerable <string> entitySets, DbInfo db)
        {
            foreach (var set in entitySets)
            {
                List <string> keys;
                if (_setToCacheKey.TryGetValue(set, out keys))
                {
                    foreach (var key in keys)
                    {
                        CacheDictionary.Remove(key);
                    }

                    _setToCacheKey.Remove(set);
                }
            }
        }
Exemplo n.º 7
0
        public void Purge(DbInfo db)
        {
            lock (_cache)
            {
                var now           = DateTimeOffset.Now;
                var itemsToRemove = new HashSet <string>();

                foreach (var item in _cache)
                {
                    if (EntryExpired(item.Value, now))
                    {
                        itemsToRemove.Add(item.Key);
                    }
                }

                foreach (var key in itemsToRemove)
                {
                    InvalidateItem(key, db);
                }
            }
        }
Exemplo n.º 8
0
        public void PutItem(string key, object value, IEnumerable <string> dependentEntitySets,
                            TimeSpan slidingExpiration, DateTimeOffset absoluteExpiration, DbInfo db)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            if (dependentEntitySets == null)
            {
                throw new ArgumentNullException("dependentEntitySets");
            }

            lock (_cache)
            {
                var entitySets = dependentEntitySets.ToArray();

                _cache[key] = new CacheEntry(value, entitySets, slidingExpiration, absoluteExpiration);

                foreach (var entitySet in entitySets)
                {
                    HashSet <string> keys;

                    if (!_entitySetToKey.TryGetValue(entitySet, out keys))
                    {
                        keys = new HashSet <string>();
                        _entitySetToKey[entitySet] = keys;
                    }

                    keys.Add(key);
                }
            }
        }
 public virtual void InvalidateSets(DbTransaction transaction, IEnumerable <string> entitySets, DbInfo db)
 {
     if (transaction == null)
     {
         _cache.InvalidateSets(entitySets, db);
     }
     else
     {
         AddAffectedEntitySets(transaction, entitySets);
     }
 }
Exemplo n.º 10
0
 public void InvalidateItem(string key, DbInfo db)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 11
0
        public void PutItem(string key, object value, IEnumerable <string> dependentEntitySets,
                            TimeSpan slidingExpiration, DateTimeOffset absoluteExpiration, DbInfo db)
        {
            CacheDictionary[key] = value;

            foreach (var set in dependentEntitySets)
            {
                List <string> keys;
                if (!_setToCacheKey.TryGetValue(set, out keys))
                {
                    keys = new List <string>();
                    _setToCacheKey[set] = keys;
                }

                keys.Add(key);
            }
        }
Exemplo n.º 12
0
 public bool GetItem(string key, out object value, DbInfo db)
 {
     return(CacheDictionary.TryGetValue(key, out value));
 }