Exemple #1
0
        /// <summary>
        /// Deletes the item from cache
        /// </summary>
        /// <param name="id">A string representing the id of the item in the cache to be deleted</param>
        /// <param name="cacheItemType">A cache item type</param>
        public override void CacheDeleteItem(string id, CacheItemType cacheItemType)
        {
            if (cacheItemType == CacheItemType.All || cacheItemType == CacheItemType.MarketDescription)
            {
                try
                {
                    foreach (var fetchedVariant in _fetchedVariants)
                    {
                        if (fetchedVariant.Key.StartsWith(id))
                        {
                            _fetchedVariants.TryRemove(id, out _);
                        }
                    }
                }
                catch (Exception e)
                {
                    ExecutionLog.LogWarning($"Error deleting fetchedVariants for {id}", e);
                }

                if (_cache.Contains(id))
                {
                    CacheLog.LogDebug($"Delete variant market: {id}");
                    _cache.Remove(id);
                }
            }
        }
Exemple #2
0
 public CacheItem(CacheItemType itemType, string itemName, object value, params string[] includingAttributes)
 {
     ItemType            = itemType;
     ItemName            = itemName;
     IncludingAttributes = includingAttributes.ToList();
     Value = value;
 }
 /// <summary>
 /// Deletes the item from cache
 /// </summary>
 /// <param name="id">A string representing the id of the item in the cache to be deleted</param>
 /// <param name="cacheItemType">A cache item type</param>
 public override void CacheDeleteItem(string id, CacheItemType cacheItemType)
 {
     if (cacheItemType == CacheItemType.All || cacheItemType == CacheItemType.MarketDescription)
     {
         _cache.Remove(id);
     }
 }
Exemple #4
0
 public DistributedCacheEntryOptions Create(CacheItemType type)
 {
     return(new DistributedCacheEntryOptions
     {
         AbsoluteExpirationRelativeToNow = _absoluteExpirationRelativeToNow
     });
 }
        /// <summary>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="cacheItemType"></param>
        /// <returns></returns>
        public T Get <T>(object key, CacheItemType cacheItemType) where T : class
        {
            string formattedKey = FormatKey(key, cacheItemType);

            var value = Cache.Get(formattedKey) as T;

            return(value);
        }
Exemple #6
0
 public async Task<ulong> GetCachedItemsSizeInBytes(CacheItemType type) {
     StorageFolder folder = await GetFolderForType(type);
     switch (type) {
         case CacheItemType.Image:
             return await GetFolderSize(folder) + await GetFolderSize(ApplicationData.Current.TemporaryFolder);
         default:
             return await GetFolderSize(folder);
     }
 }
Exemple #7
0
 /// <summary>
 ///     Deletes the item from cache
 /// </summary>
 /// <param name="id">A string representing the id of the item in the cache to be deleted</param>
 /// <param name="cacheItemType">A cache item type</param>
 public override void CacheDeleteItem(string id, CacheItemType cacheItemType)
 {
     if (cacheItemType == CacheItemType.All || cacheItemType == CacheItemType.MarketDescription)
     {
         DateTime date;
         _fetchedVariants.TryRemove(id, out date);
         _cache.Remove(id);
     }
 }
 /// <summary>
 /// Deletes the item from cache
 /// </summary>
 /// <param name="id">A <see cref="URN" /> representing the id of the item in the cache to be deleted</param>
 /// <param name="cacheItemType">A cache item type</param>
 public override void CacheDeleteItem(URN id, CacheItemType cacheItemType)
 {
     if (cacheItemType == CacheItemType.All ||
         cacheItemType == CacheItemType.Competitor ||
         cacheItemType == CacheItemType.Player)
     {
         _cache.Remove(id.ToString());
     }
 }
Exemple #9
0
        public async Task DeleteItemAsync(string uri, CacheItemType type = CacheItemType.Other) {
            StorageFolder folder = await GetFolderForType(type);
            string name = Hashing.Sha256(uri) + Path.GetExtension(uri);
            IStorageItem item = await folder.TryGetItemAsync(name);
            if (item != null) {
                await item.DeleteAsync();
            }

        }
        /// <summary>
        /// Does item exists in the cache
        /// </summary>
        /// <param name="id">A string representing the id of the item to be checked</param>
        /// <param name="cacheItemType">A cache item type</param>
        /// <returns><c>true</c> if exists, <c>false</c> otherwise</returns>
        public override bool CacheHasItem(string id, CacheItemType cacheItemType)
        {
            if (cacheItemType == CacheItemType.All || cacheItemType == CacheItemType.MarketDescription)
            {
                return(_cache.Contains(id));
            }

            return(false);
        }
 /// <summary>
 /// Does item exists in the cache
 /// </summary>
 /// <param name="id">A <see cref="URN" /> representing the id of the item to be checked</param>
 /// <param name="cacheItemType">A cache item type</param>
 /// <returns><c>true</c> if exists, <c>false</c> otherwise</returns>
 public override bool CacheHasItem(URN id, CacheItemType cacheItemType)
 {
     if (cacheItemType == CacheItemType.All ||
         cacheItemType == CacheItemType.Competitor ||
         cacheItemType == CacheItemType.Player)
     {
         return(_cache.Contains(id.ToString()));
     }
     return(false);
 }
 /// <summary>
 /// Deletes the item from cache
 /// </summary>
 /// <param name="id">A <see cref="URN" /> representing the id of the item in the cache to be deleted</param>
 /// <param name="cacheItemType">A cache item type</param>
 public override void CacheDeleteItem(URN id, CacheItemType cacheItemType)
 {
     if (id != null)
     {
         if (cacheItemType == CacheItemType.All || cacheItemType == CacheItemType.MarketDescription)
         {
             _cache.Remove(id.Id.ToString());
         }
     }
 }
Exemple #13
0
 public void add_dependency(DependencyType depType, string depid, CacheItemType itemType, string itemid)
 {
     // if null then just add independent cache entry
     string cacheKey = CreateCacheItemKey(itemType, itemid);
     string dependencyKey = CreateDependencyKey(depType, depid);
     if (!dep_map.ContainsKey(dependencyKey))
     {
         dep_map.Add(dependencyKey, new HashSet<string>());
     }
     dep_map[dependencyKey].Add(cacheKey);
 }
Exemple #14
0
        private async Task<StorageFile> GetOrCreateFile(string url, CacheItemType type) {
            StorageFolder folder = await GetFolderForType(type);
            string name = Hashing.Sha256(url) + Path.GetExtension(url);
            IStorageItem item = await folder.TryGetItemAsync(name);
            var storageFile = item as StorageFile;
            if (storageFile != null) {
                return storageFile;
            }

            return await folder.CreateFileAsync(name, CreationCollisionOption.ReplaceExisting);
        }
Exemple #15
0
 /// <summary>
 /// Deletes the item from cache
 /// </summary>
 /// <param name="id">A <see cref="URN" /> representing the id of the item in the cache to be deleted</param>
 /// <param name="cacheItemType">A cache item type</param>
 public override void CacheDeleteItem(URN id, CacheItemType cacheItemType)
 {
     if (id != null)
     {
         if (cacheItemType == CacheItemType.All || cacheItemType == CacheItemType.MarketDescription)
         {
             CacheLog.LogDebug($"Delete variant market: {id}");
             _cache.Remove(id.Id.ToString());
         }
     }
 }
Exemple #16
0
 public object GetCachedItem(CacheItemType itemType, string itemName, params string[] keys)
 {
     if (keys.Count(x => !string.IsNullOrEmpty(x)) > 0)
     {
         return(cacheItems.FirstOrDefault(x => x.ItemType == itemType && x.ItemName == itemName && keys.Where(k => !string.IsNullOrEmpty(k)).All(y => x.IncludingAttributes.Any(z => z == y)))?.Value);
     }
     else
     {
         return(cacheItems.FirstOrDefault(x => x.ItemType == itemType && x.ItemName == itemName)?.Value);
     }
 }
 /// <summary>
 /// Does item exists in the cache
 /// </summary>
 /// <param name="id">A <see cref="URN" /> representing the id of the item to be checked</param>
 /// <param name="cacheItemType">A cache item type</param>
 /// <returns><c>true</c> if exists, <c>false</c> otherwise</returns>
 public override bool CacheHasItem(URN id, CacheItemType cacheItemType)
 {
     if (id != null)
     {
         if (cacheItemType == CacheItemType.All || cacheItemType == CacheItemType.MarketDescription)
         {
             return(_cache.Contains(id.Id.ToString()));
         }
     }
     return(false);
 }
Exemple #18
0
 /// <summary>
 ///     Deletes the item from cache
 /// </summary>
 /// <param name="id">A string representing the id of the item in the cache to be deleted</param>
 /// <param name="cacheItemType">A cache item type</param>
 /// <exception cref="System.NotImplementedException"></exception>
 public virtual void CacheDeleteItem(string id, CacheItemType cacheItemType)
 {
     try
     {
         var urn = URN.Parse(id);
         CacheDeleteItem(urn, cacheItemType);
     }
     catch (Exception)
     {
         // ignored
     }
 }
Exemple #19
0
        public async Task ClearCache(CacheItemType type) {
            StorageFolder folder = await GetFolderForType(type);
            IReadOnlyList<IStorageItem> items = await folder.GetItemsAsync();
            if (type == CacheItemType.Image) {
                StorageFolder additionalFolder = ApplicationData.Current.TemporaryFolder;
                items = items.Concat(await additionalFolder.GetItemsAsync()).ToList();
            }

            foreach (IStorageItem item in items) {
                await item.DeleteAsync(StorageDeleteOption.PermanentDelete);
            }
        }
Exemple #20
0
 /// <summary>
 /// Purges item from cache
 /// </summary>
 /// <param name="id">A <see cref="URN"/> representing the id of the sport event which to be deleted</param>
 /// <param name="cacheItemType">The cache item type to be deleted</param>
 public override void CacheDeleteItem(URN id, CacheItemType cacheItemType)
 {
     lock (_addLock)
     {
         if (cacheItemType == CacheItemType.All ||
             cacheItemType == CacheItemType.SportEvent ||
             cacheItemType == CacheItemType.Tournament)
         {
             Cache.Remove(id.ToString());
         }
     }
 }
Exemple #21
0
        /// <summary>
        /// Does item exists in the cache
        /// </summary>
        /// <param name="id">A <see cref="URN" /> representing the id of the item to be checked</param>
        /// <param name="cacheItemType">A cache item type</param>
        /// <returns><c>true</c> if exists, <c>false</c> otherwise</returns>
        public override bool CacheHasItem(URN id, CacheItemType cacheItemType)
        {
            if (cacheItemType == CacheItemType.Sport || cacheItemType == CacheItemType.All)
            {
                return(Sports.ContainsKey(id));
            }

            if (cacheItemType == CacheItemType.Category || cacheItemType == CacheItemType.All)
            {
                return(Categories.ContainsKey(id));
            }
            return(false);
        }
Exemple #22
0
 /// <summary>
 /// Does item exists in the cache
 /// </summary>
 /// <param name="id">A <see cref="URN" /> representing the id of the item to be checked</param>
 /// <param name="cacheItemType">A cache item type</param>
 /// <returns><c>true</c> if exists, <c>false</c> otherwise</returns>
 public override bool CacheHasItem(URN id, CacheItemType cacheItemType)
 {
     lock (_addLock)
     {
         if (cacheItemType == CacheItemType.All ||
             cacheItemType == CacheItemType.SportEvent ||
             cacheItemType == CacheItemType.Tournament)
         {
             return(Cache.Contains(id.ToString()));
         }
         return(false);
     }
 }
        /// <summary>
        /// </summary>
        /// <param name="key"></param>
        /// <param name="cacheItemType"></param>
        /// <returns></returns>
        public bool Remove(object key, CacheItemType cacheItemType)
        {
            string formattedKey = FormatKey(key, cacheItemType);

            object removedItem = Cache.Remove(formattedKey);

            if (removedItem != null)
            {
                return(true);
            }

            return(false);
        }
Exemple #24
0
 /// <summary>
 /// Does item exists in the cache
 /// </summary>
 /// <param name="id">A string representing the id of the item to be checked</param>
 /// <param name="cacheItemType">A cache item type</param>
 /// <returns><c>true</c> if exists, <c>false</c> otherwise</returns>
 /// <exception cref="System.NotImplementedException"></exception>
 public virtual bool CacheHasItem(string id, CacheItemType cacheItemType)
 {
     try
     {
         var urn = URN.Parse(id);
         return(CacheHasItem(urn, cacheItemType));
     }
     catch (Exception)
     {
         // ignored
     }
     return(false);
 }
Exemple #25
0
        public string Insert(CacheItemType type, string id, object value)
        {
            if (value == null)
            {
                return null;
            }

            string key = CreateCacheItemKey(type, id);
            // add with no sliding or absolute expiration
            // cache dependencies are manually handled
            HttpRuntime.Cache.Insert(key,value);

            return key;
        }
        /// <summary>
        /// Purges item from cache
        /// </summary>
        /// <param name="id">A <see cref="URN" /> representing the id of the item in the cache to be purged</param>
        /// <param name="cacheItemType">A cache item type</param>
        public override void CacheDeleteItem(URN id, CacheItemType cacheItemType)
        {
            Guard.Argument(id, nameof(id)).NotNull();

            if (_isDisposed)
            {
                return;
            }

            if (cacheItemType == CacheItemType.All || cacheItemType == CacheItemType.SportEventStatus)
            {
                _sportEventStatusCache.Remove(id.ToString());
            }
        }
Exemple #27
0
        /// <summary>
        /// Deletes the item from cache
        /// </summary>
        /// <param name="id">A string representing the id of the item in the cache to be deleted</param>
        /// <param name="cacheItemType">A cache item type</param>
        /// <exception cref="NotImplementedException"></exception>
        public virtual void CacheDeleteItem(string id, CacheItemType cacheItemType)
        {
            Guard.Argument(id, nameof(id)).NotNull().NotEmpty();

            try
            {
                var urn = URN.Parse(id);
                CacheDeleteItem(urn, cacheItemType);
            }
            catch (Exception)
            {
                // ignored
            }
        }
Exemple #28
0
        /// <summary>
        ///     Purges item from cache
        /// </summary>
        /// <param name="id">A <see cref="URN" /> representing the id of the item in the cache to be purged</param>
        /// <param name="cacheItemType">A cache item type</param>
        public override void CacheDeleteItem(URN id, CacheItemType cacheItemType)
        {
            if (_isDisposed)
            {
                return;
            }

            if (cacheItemType == CacheItemType.All || cacheItemType == CacheItemType.SportEventStatus)
            {
                lock (_lock)
                {
                    _sportEventStatusCache.Remove(id.ToString());
                }
            }
        }
Exemple #29
0
        /// <summary>
        /// Does item exists in the cache
        /// </summary>
        /// <param name="id">A string representing the id of the item to be checked</param>
        /// <param name="cacheItemType">A cache item type</param>
        /// <returns><c>true</c> if exists, <c>false</c> otherwise</returns>
        /// <exception cref="NotImplementedException"></exception>
        public virtual bool CacheHasItem(string id, CacheItemType cacheItemType)
        {
            Guard.Argument(id, nameof(id)).NotNull().NotEmpty();

            try
            {
                var urn = URN.Parse(id);
                return(CacheHasItem(urn, cacheItemType));
            }
            catch (Exception)
            {
                // ignored
            }
            return(false);
        }
        /// <summary>
        /// Does item exists in the cache
        /// </summary>
        /// <param name="id">A <see cref="URN" /> representing the id of the item to be checked</param>
        /// <param name="cacheItemType">A cache item type</param>
        /// <returns><c>true</c> if exists, <c>false</c> otherwise</returns>
        public override bool CacheHasItem(URN id, CacheItemType cacheItemType)
        {
            Guard.Argument(id, nameof(id)).NotNull();

            if (_isDisposed)
            {
                return(false);
            }
            var result = false;

            if (cacheItemType == CacheItemType.All || cacheItemType == CacheItemType.SportEventStatus)
            {
                result = _sportEventStatusCache.Contains(id.ToString());
            }
            return(result);
        }
Exemple #31
0
        public bool TryGetCache(CacheItemType type, string id, out object value)
        {
            string key = CreateCacheItemKey(type, id);
            
            // anything in cache
            object data = HttpRuntime.Cache.Get(key);

            // yes, return cached entry
            if (data == null)
            {
                value = null;
                return false;
            }
            value = data;
            return true;
        }
Exemple #32
0
        /// <summary>
        /// Does item exists in the cache
        /// </summary>
        /// <param name="id">A <see cref="URN" /> representing the id of the item to be checked</param>
        /// <param name="cacheItemType">A cache item type</param>
        /// <returns><c>true</c> if exists, <c>false</c> otherwise</returns>
        public override bool CacheHasItem(URN id, CacheItemType cacheItemType)
        {
            if (_isDisposed)
            {
                return(false);
            }
            var result = false;

            if (cacheItemType == CacheItemType.All || cacheItemType == CacheItemType.SportEventStatus)
            {
                lock (_lock)
                {
                    result = _sportEventStatusCache.Contains(id.ToString());
                }
            }
            return(result);
        }
        /// <summary>
        ///     Remove the cache item in the all registered caches
        /// </summary>
        /// <param name="id">The identifier of the item</param>
        /// <param name="cacheItemType">Type of the cache item</param>
        /// <param name="sender">The name of the cache or class that is initiating request</param>
        public void RemoveCacheItem(URN id, CacheItemType cacheItemType, string sender)
        {
            Contract.Requires(id != null);

            if (_caches == null || !_caches.Any())
            {
                ExecLog.Warn("Cannot remove item from cache. There is no registered cache.");
                return;
            }

            var caches = _caches.Where(c => !c.Value.CacheName.Equals(sender));

            foreach (var cache in caches)
            {
                cache.Value.CacheDeleteItem(id, cacheItemType);
            }
        }
        /// <summary>
        /// Remove the cache item in the all registered caches
        /// </summary>
        /// <param name="id">The identifier of the item</param>
        /// <param name="cacheItemType">Type of the cache item</param>
        /// <param name="sender">The name of the cache or class that is initiating request</param>
        public void RemoveCacheItem(URN id, CacheItemType cacheItemType, string sender)
        {
            Guard.Argument(id, nameof(id)).NotNull();

            if (_caches == null || !_caches.Any())
            {
                ExecLog.Warn("Cannot remove item from cache. There is no registered cache.");
                return;
            }

            var caches = _caches.Where(c => !c.Value.CacheName.Equals(sender));

            foreach (var cache in caches)
            {
                cache.Value.CacheDeleteItem(id, cacheItemType);
            }
        }
Exemple #35
0
 private async Task<StorageFolder> GetFolderForType(CacheItemType itemType) {
     var baseFolder = ApplicationData.Current.LocalCacheFolder;
     return await baseFolder.CreateFolderAsync(itemType.ToString(), CreationCollisionOption.OpenIfExists);
 }
Exemple #36
0
 public async Task<IRandomAccessStream> RetrieveStreamAsync(string url,
                                                            CacheItemType type = CacheItemType.Other,
                                                            Action<int> onProgress = null) {
     StorageFile newFile = await GetOrCreateFile(url, type);
     return await DownloadAndGetStream(url, newFile, onProgress);
 }
Exemple #37
0
 public async Task<StorageFile> RetrieveFileAsync(string url, CacheItemType type = CacheItemType.Other,
                                                      Action<int> onProgress = null) {
     StorageFile newFile = await GetOrCreateFile(url, type);
     await DownloadToFile(url, newFile, onProgress);
     return newFile;
 }
Exemple #38
0
 private async Task ClearCache(CacheItemType type) {
     try {
         await CacheService.ClearCache(type);
         await CalculateCache();
     }
     catch {
         // It's ok
     }
 }