/// <summary>
        /// Retrieves the path & name of the cache entry file
        /// </summary>
        /// <param name="identifiers"></param>
        /// <returns></returns>
        private FileInfo GetCacheEntryFile(params object[] identifiers)
        {
            var md5 = CacheBase.GetChecksum(identifiers).ToString();

            return(new FileInfo(
                       Path.Combine(
                           this.CacheDirectory.FullName,
                           md5.Substring(0, 2),
                           md5 + ".cachefile")));
        }
Beispiel #2
0
        public CacheEntry Retrieve(params object[] identifiers)
        {
            var md5 = CacheBase.GetChecksum(identifiers);
            MemoryCacheEntry ce;

            if (!this.entries.TryGetValue(md5, out ce))
            {
                return(CacheEntry.Empty);
            }
            ce.LastAccess = DateTime.Now;
            return(ce);
        }
Beispiel #3
0
        public void Store(CacheEntry cacheEntry, params object[] identifiers)
        {
            if (cacheEntry.Data == null)
            {
                return;
            }

            MemoryCacheEntry newEntry = new MemoryCacheEntry(cacheEntry);
            var size = newEntry.Data.Length + 24;

            if (size > this.MaxSize)
            {
                // Data is larger than our maximum size.
                return;
            }

            var md5 = CacheBase.GetChecksum(identifiers);

            if (this.Available < 0)
            {
                this.RemoveStaleItems();
                this.Trim(size);
            }

            if (this.entries.ContainsKey(md5))
            {
                MemoryCacheEntry ce;
                this.entries.TryRemove(md5, out ce);
                lock (this)
                {
                    this.Size -= ce.Data.Length + 24;
                }
            }
            this.entries.TryAdd(md5, newEntry);
            lock (this)
            {
                this.Size += size;
            }
        }