コード例 #1
0
        public void Invalidate(string className, object primaryKeyValue, SoodaCacheInvalidateReason reason)
        {
            if (logger.IsTraceEnabled)
            {
                logger.Trace("Invalidating object {0}({1}). Reason: {2}", className, primaryKeyValue, reason);
            }

            _rwlock.AcquireWriterLock(-1);
            try
            {
                SoodaCacheKey cacheKey = new SoodaCacheKey(className, primaryKeyValue);
                _objectCache.Remove(cacheKey);

                LruCache cachedCollectionsDependentOnClass = (LruCache)_collectionsDependentOnClass[className];
                if (cachedCollectionsDependentOnClass != null)
                {
                    foreach (string key in cachedCollectionsDependentOnClass.Keys)
                    {
                        _collectionCache.Remove(key);
                    }
                    cachedCollectionsDependentOnClass.Clear();
                }
            }
            finally
            {
                _rwlock.ReleaseWriterLock();
            }
        }
コード例 #2
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);
                }
            }
        }
コード例 #3
0
 public SoodaCacheEntry Find(string className, object primaryKeyValue)
 {
     _rwlock.AcquireReaderLock(-1);
     try
     {
         SoodaCacheKey cacheKey = new SoodaCacheKey(className, primaryKeyValue);
         return (SoodaCacheEntry)_objectCache.Get(cacheKey);
     }
     finally
     {
         _rwlock.ReleaseReaderLock();
     }
 }
コード例 #4
0
 public SoodaCacheEntry Find(string className, object primaryKeyValue)
 {
     _rwlock.AcquireReaderLock(-1);
     try
     {
         SoodaCacheKey cacheKey = new SoodaCacheKey(className, primaryKeyValue);
         return((SoodaCacheEntry)_objectCache.Get(cacheKey));
     }
     finally
     {
         _rwlock.ReleaseReaderLock();
     }
 }
コード例 #5
0
 public void Add(string className, object primaryKeyValue, SoodaCacheEntry entry, TimeSpan expirationTimeout, bool slidingExpiration)
 {
     _rwlock.AcquireWriterLock(-1);
     try
     {
         SoodaCacheKey cacheKey = new SoodaCacheKey(className, primaryKeyValue);
         _objectCache.Set(cacheKey, entry, expirationTimeout, slidingExpiration);
         if (logger.IsTraceEnabled)
         {
             logger.Trace("Adding {0} to cache.", cacheKey);
         }
     }
     finally
     {
         _rwlock.ReleaseWriterLock();
     }
 }
コード例 #6
0
        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();
                }
            }
        }
コード例 #7
0
 public void Add(string className, object primaryKeyValue, SoodaCacheEntry entry, TimeSpan expirationTimeout, bool slidingExpiration)
 {
     _rwlock.AcquireWriterLock(-1);
     try
     {
         SoodaCacheKey cacheKey = new SoodaCacheKey(className, primaryKeyValue);
         _objectCache.Set(cacheKey, entry, expirationTimeout, slidingExpiration);
         if (logger.IsTraceEnabled)
         {
             logger.Trace("Adding {0} to cache.", cacheKey);
         }
     }
     finally
     {
         _rwlock.ReleaseWriterLock();
     }
 }
コード例 #8
0
        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();
                }
            }
        }
コード例 #9
0
        public void Invalidate(string className, object primaryKeyValue, SoodaCacheInvalidateReason reason)
        {
            if (logger.IsTraceEnabled)
            {
                logger.Trace("Invalidating object {0}({1}). Reason: {2}", className, primaryKeyValue, reason);
            }

            _rwlock.AcquireWriterLock(-1);
            try
            {
                SoodaCacheKey cacheKey = new SoodaCacheKey(className, primaryKeyValue);
                _objectCache.Remove(cacheKey);

                LruCache cachedCollectionsDependentOnClass = (LruCache)_collectionsDependentOnClass[className];
                if (cachedCollectionsDependentOnClass != null)
                {
                    foreach (string key in cachedCollectionsDependentOnClass.Keys)
                    {
                        _collectionCache.Remove(key);
                    }
                    cachedCollectionsDependentOnClass.Clear();
                }
            }
            finally
            {
                _rwlock.ReleaseWriterLock();
            }
        }