/// <summary> /// Gets the time to live of a cached object. /// </summary> /// <typeparam name="T">The type of the object.</typeparam> /// <param name="key">The key of the object.</param> /// <param name="options">Supplies virtual cache type, if any.</param> /// <returns>A <see cref="Nullable{DateTime}"/> containing the expiration /// time if found; otherwise <see langword="null"/>.</returns> /// <exception cref="ArgumentException"> /// <para>Type of <see cref="StorageKey.Key"/> of <paramref name="key"/> /// is wrong for the cache type of <typeparamref name="T"/>. /// </para> /// </exception> /// <exception cref="ApplicationException"> /// <typeparamref name="T"/> is a virtual cache type and <paramref name="options"/> /// has a null <see cref="LocalCacheOptions.VirtualCacheObject"/>. /// </exception> public static DateTime?GetExpires <T>(StorageKey key, LocalCacheOptions options) where T : ICacheParameter { CacheTypeStatic <T> .AssertProperStorageKey(key); return(GetExpires( GetKeySpace <T>(options.VirtualCacheObject), key)); }
/// <summary> /// Generates a reference to an object by identifier. /// </summary> /// <typeparam name="T">The type of the object. Must not /// implement <see cref="IExtendedCacheParameter"/> or /// <see cref="IExtendedRawCacheParameter"/>.</typeparam> /// <param name="objectId">The <see cref="StorageKey"/> /// of the object.</param> /// <param name="options">Supplies virtual cache type, if any.</param> /// <returns>The <see cref="ObjectReference"/> that specifies /// the object.</returns> /// <exception cref="ArgumentException"> /// <para>Type of <see cref="StorageKey.Key"/> of <paramref name="objectId"/> /// is wrong for the cache type of <typeparamref name="T"/>. /// </para> /// </exception> /// <exception cref="ApplicationException"> /// <typeparamref name="T"/> is a virtual cache type and <paramref name="options"/> /// has a null <see cref="LocalCacheOptions.VirtualCacheObject"/>. /// </exception> public static ObjectReference CreateReference <T>(StorageKey objectId, LocalCacheOptions options) where T : ICacheParameter { CacheTypeStatic <T> .AssertProperStorageKey(objectId); return(new ObjectReference(GetKeySpace <T>(options.VirtualCacheObject), objectId)); }
/// <summary> /// Retrieves an object from cache. /// </summary> /// <typeparam name="T">The type of the object.</typeparam> /// <param name="key">The key of the object.</param> /// <param name="options">The <see cref="LocalCacheOptions"/> to use for this /// operation.</param> /// <returns><see langword="true"/> if the object was found, otherwise /// <see langword="false"/>.</returns> /// <exception cref="ArgumentException"> /// <para>Type of <see cref="StorageKey.Key"/> of <paramref name="key"/> /// is wrong for the cache type of <typeparamref name="T"/>. /// </para> /// </exception> /// <exception cref="ApplicationException"> /// <typeparamref name="T"/> is a virtual cache type and <paramref name="options"/> /// has a null <see cref="LocalCacheOptions.VirtualCacheObject"/>. /// </exception> public static StorageEntry <T> Get <T>(StorageKey key, LocalCacheOptions options) where T : ICacheParameter { if (!IsLocalCachingConfigured()) { return(StorageEntry <T> .NotFound); } CacheTypeStatic <T> .AssertProperStorageKey(key); var entry = _storage.Get(GetKeySpace <T>(options.VirtualCacheObject), key, TypeStatic <T> .Creator); if (entry.IsFound) { entry.Instance.DataSource = DataSource.Cache; } return(entry); }
/// <summary> /// Deletes a cached object. /// </summary> /// <typeparam name="T">The type of the object.</typeparam> /// <param name="key">The key of the object.</param> /// <param name="options">Supplies virtual cache type, if any.</param> /// <returns><see langword="true"/> if the object existed prior, otherwise /// <see langword="false"/>.</returns> /// <exception cref="ArgumentException"> /// <para>Type of <see cref="StorageKey.Key"/> of <paramref name="key"/> /// is wrong for the cache type of <typeparamref name="T"/>. /// </para> /// </exception> /// <exception cref="ApplicationException"> /// <typeparamref name="T"/> is a virtual cache type and <paramref name="options"/> /// has a null <see cref="LocalCacheOptions.VirtualCacheObject"/>. /// </exception> public static bool Delete <T>(StorageKey key, LocalCacheOptions options) where T : ICacheParameter { CacheTypeStatic <T> .AssertProperStorageKey(key); return(Delete(GetKeySpace <T>(options.VirtualCacheObject), key)); }