public void InvalidateCollection(SoodaCachedCollection collection)
        {
            LruCache cachedCollectionsDependentOnClass =
                (LruCache)_collectionsDependentOnClass[collection.RootClassName];

            cachedCollectionsDependentOnClass.Remove(collection.CollectionKey);
            _collectionCache.Remove(collection.CollectionKey);
        }
Exemplo n.º 2
0
 public void RegisterDependentCollection(SoodaCachedCollection key)
 {
     if (_dependentCollections == null)
     {
         _dependentCollections = new ArrayList();
     }
     _dependentCollections.Add(key);
 }
Exemplo n.º 3
0
        public void FillSnapshotTable(DataSet dataSet, string tableName)
        {
            lock (this)
            {
                DataTable dt = dataSet.Tables.Add(tableName);
                dt.Columns.Add("LruPosition", typeof(int));
                dt.Columns.Add("Class", typeof(string));
                dt.Columns.Add("Key", typeof(string));
                dt.Columns.Add("Value", typeof(string));
                dt.Columns.Add("AddedTime", typeof(DateTime));
                dt.Columns.Add("LastAccessTime", typeof(DateTime));
                dt.Columns.Add("ExpirationTime", typeof(DateTime));
                dt.Columns.Add("UsedCount", typeof(int));

                int pos = 0;

                for (LruCacheNode node = _lruHead; node != null; node = node.Next)
                {
                    DataRow row = dt.NewRow();

                    string className;
                    string keyValue;

                    SoodaCacheKey         ck1 = node.Key as SoodaCacheKey;
                    SoodaCachedCollection scc = node.Value as SoodaCachedCollection;

                    if (ck1 != null)
                    {
                        className = ck1.ClassName;
                        keyValue  = Convert.ToString(ck1.KeyValue);
                    }
                    else if (scc != null)
                    {
                        className = scc.RootClassName;
                        keyValue  = scc.CollectionKey;
                    }
                    else
                    {
                        className = Convert.ToString(node.Key);
                        keyValue  = null;
                    }

                    row.ItemArray = new object[]
                    {
                        pos++,
                        className,
                        keyValue,
                        Convert.ToString(node.Value),
                        node.AddedTime,
                        node.LastAccessTime,
                        node.ExpirationTime,
                        node.UsedCount
                    };
                    dt.Rows.Add(row);
                }
            }
        }
        public void StoreCollection(string cacheKey, string rootClassName, IList primaryKeys, string[] dependentClassNames, bool evictWhenItemRemoved, TimeSpan expirationTimeout, bool slidingExpiration)
        {
            if (cacheKey != null)
            {
                _rwlock.AcquireWriterLock(-1);
                try
                {
                    if (logger.IsTraceEnabled)
                    {
                        logger.Trace("Storing collection: {0} {1} items. Dependent on: [ {2} ]", cacheKey, primaryKeys.Count, String.Join(",", dependentClassNames));
                    }

                    SoodaCachedCollection cc = new SoodaCachedCollection(cacheKey, rootClassName, primaryKeys);

                    if (evictWhenItemRemoved)
                    {
                        foreach (object o in primaryKeys)
                        {
                            SoodaCacheKey   k = new SoodaCacheKey(rootClassName, o);
                            SoodaCacheEntry e = (SoodaCacheEntry)_objectCache[k];
                            if (e != null)
                            {
                                //logger.Trace("Registering {0} as dependent of {1}", cacheKey, e);
                                e.RegisterDependentCollection(cc);
                            }
                            ;
                        }
                    }
                    _collectionCache.Set(cacheKey, cc, expirationTimeout, slidingExpiration);

                    RegisterDependentCollectionClass(cacheKey, rootClassName, expirationTimeout, slidingExpiration);
                    if (dependentClassNames != null)
                    {
                        for (int i = 0; i < dependentClassNames.Length; ++i)
                        {
                            RegisterDependentCollectionClass(cacheKey, dependentClassNames[i], expirationTimeout, slidingExpiration);
                        }
                    }
                }
                finally
                {
                    _rwlock.ReleaseWriterLock();
                }
            }
        }
        public IList LoadCollection(string key)
        {
            if (key == null)
            {
                return(null);
            }

            SoodaCachedCollection cc = (SoodaCachedCollection)_collectionCache[key];

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

            IList retval = cc.PrimaryKeys;

            logger.Trace("Collection: {0} retrieved from cache: {1} items", key, retval.Count);
            return(retval);
        }
Exemplo n.º 6
0
 public void RegisterDependentCollection(SoodaCachedCollection key)
 {
     if (_dependentCollections == null)
         _dependentCollections = new ArrayList();
     _dependentCollections.Add(key);
 }
        public void StoreCollection(string cacheKey, string rootClassName, IList primaryKeys, string[] dependentClassNames, bool evictWhenItemRemoved, TimeSpan expirationTimeout, bool slidingExpiration)
        {
            if (cacheKey != null)
            {
                _rwlock.AcquireWriterLock(-1);
                try
                {
                    if (logger.IsTraceEnabled)
                    {
                        logger.Trace("Storing collection: {0} {1} items. Dependent on: [ {2} ]", cacheKey, primaryKeys.Count, String.Join(",",dependentClassNames));
                    }

                    SoodaCachedCollection cc = new SoodaCachedCollection(cacheKey, rootClassName, primaryKeys);

                    if (evictWhenItemRemoved)
                    {
                        foreach (object o in primaryKeys)
                        {
                            SoodaCacheKey k = new SoodaCacheKey(rootClassName, o);
                            SoodaCacheEntry e = (SoodaCacheEntry)_objectCache[k];
                            if (e != null)
                            {
                                //logger.Trace("Registering {0} as dependent of {1}", cacheKey, e);
                                e.RegisterDependentCollection(cc);
                            };
                        }
                    }
                    _collectionCache.Set(cacheKey, cc, expirationTimeout, slidingExpiration);

                    RegisterDependentCollectionClass(cacheKey, rootClassName, expirationTimeout, slidingExpiration);
                    if (dependentClassNames != null)
                    {
                        for (int i = 0; i < dependentClassNames.Length; ++i)
                        {
                            RegisterDependentCollectionClass(cacheKey, dependentClassNames[i], expirationTimeout, slidingExpiration);
                        }
                    }
                }
                finally
                {
                    _rwlock.ReleaseWriterLock();
                }
            }
        }
 public void InvalidateCollection(SoodaCachedCollection collection)
 {
     LruCache cachedCollectionsDependentOnClass =
         (LruCache) _collectionsDependentOnClass[collection.RootClassName];
     cachedCollectionsDependentOnClass.Remove(collection.CollectionKey);
     _collectionCache.Remove(collection.CollectionKey);
 }