Beispiel #1
0
        private byte[] GetFromRemote(CacheSettings cs, string path)
        {
            var data = GetFromRemote(path);

            if (cs.Cached)
            {
                cs.CacheDependency = CacheHelper.GetCacheDependency(BlobCacheHelper.GetCacheDependency(path));
            }

            return(data);
        }
Beispiel #2
0
        private void AddToCache(string path, byte[] data, DateTime created)
        {
            switch (_cacheType)
            {
            case BlobCacheType.Memory:
                CacheHelper.Add(BlobCacheHelper.GetCacheKey(path), data, CacheHelper.GetCacheDependency(BlobCacheHelper.GetCacheDependency(path)), DateTime.Now.AddMinutes(AccountInfo.Instance.BlobCacheMinutes), System.Web.Caching.Cache.NoSlidingExpiration);
                break;

            case BlobCacheType.FileSystem:
                AddToFileSystem(path, data, created);
                break;
            }
        }
Beispiel #3
0
        public void Discard(string path)
        {
            switch (_cacheType)
            {
            case BlobCacheType.Memory:
                CacheHelper.TouchKey(BlobCacheHelper.GetCacheDependency(path));
                break;

            case BlobCacheType.FileSystem:
                var tempFilePath = AzurePathHelper.GetTempBlobPath(path);
                if (System.IO.File.Exists(tempFilePath))
                {
                    System.IO.File.Delete(tempFilePath);
                }
                break;
            }
        }
Beispiel #4
0
        public byte[] Get(string path, DateTime remoteLastModified)
        {
            if (_cacheType == BlobCacheType.None || _excludedPaths.Any(p => path.StartsWith(p, StringComparison.OrdinalIgnoreCase)))
            {
                return(GetFromRemote(path));
            }

            byte[] data = null;

            switch (CacheType)
            {
            case BlobCacheType.Memory:
                data = CacheHelper.Cache(cs => GetFromRemote(cs, path), new CacheSettings(AccountInfo.Instance.BlobCacheMinutes, BlobCacheHelper.GetCacheKey(path)));
                break;

            case BlobCacheType.FileSystem:
                data = TryGetFromFileSystemCache(path, remoteLastModified);

                if (data == null)
                {
                    data = GetFromRemote(path);
                    AddToCache(path, data, DateTime.UtcNow);
                }
                break;
            }

            return(data);
        }