public static GetItem ( string key, string regionName = null ) : object | ||
key | string | /// A unique identifier for the cache entry. /// |
regionName | string | /// Optional. A named region in the cache to which the cache entry can be added, /// if regions are implemented. The default value for the optional parameter /// is null. /// |
Résultat | object |
/// <summary> /// Gets the <see cref="CachedImage"/> associated with the specified key. /// </summary> /// <param name="cachedPath"> /// The cached path of the value to get. /// </param> /// <returns> /// The <see cref="CachedImage"/> matching the given key if the <see cref="CacheIndexer"/> contains an element with /// the specified key; otherwise, null. /// </returns> public static CachedImage Get(string cachedPath) { string key = Path.GetFileNameWithoutExtension(cachedPath); CachedImage cachedImage = (CachedImage)MemCache.GetItem(key); return(cachedImage); }
/// <summary> /// Gets the <see cref="CachedImage"/> associated with the specified key. /// </summary> /// <param name="cachedPath"> /// The cached path of the value to get. /// </param> /// <returns> /// The <see cref="CachedImage"/> matching the given key if the <see cref="CacheIndexer"/> contains an element with /// the specified key; otherwise, null. /// </returns> public static CachedImage GetValue(string cachedPath) { string key = Path.GetFileNameWithoutExtension(cachedPath); CachedImage cachedImage = (CachedImage)MemCache.GetItem(key); if (cachedImage == null) { // FileInfo is thread safe. FileInfo fileInfo = new FileInfo(cachedPath); if (!fileInfo.Exists) { return(null); } // Pull the latest info. fileInfo.Refresh(); cachedImage = new CachedImage { Key = Path.GetFileNameWithoutExtension(cachedPath), Path = cachedPath, CreationTimeUtc = fileInfo.CreationTimeUtc }; Add(cachedImage); } return(cachedImage); }
/// <summary> /// Gets the <see cref="CachedImage"/> associated with the specified key. /// </summary> /// <param name="cachedPath"> /// The cached path of the value to get. /// </param> /// <returns> /// The <see cref="CachedImage"/> matching the given key if the <see cref="CacheIndexer"/> contains an element with /// the specified key; otherwise, null. /// </returns> public static async Task <CachedImage> GetValueAsync(string cachedPath) { string key = Path.GetFileNameWithoutExtension(cachedPath); CachedImage cachedImage = (CachedImage)MemCache.GetItem(key); if (cachedImage == null) { cachedImage = await TaskHelpers.Run(() => GetCachedImage(cachedPath)); if (cachedImage != null) { Add(cachedImage); } } return(cachedImage); }