Esempio n. 1
0
        /// <summary>
        /// Asynchronously gets a string from the specified cache with the specified key.
        /// </summary>
        /// <param name="cache">The cache in which to store the data.</param>
        /// <param name="key">The key to get the stored data for.</param>
        /// <param name="token">Optional. A <see cref="CancellationToken" /> to cancel the operation.</param>
        /// <returns>A task that gets the string value from the stored cache key.</returns>
        public static async Task <string> GetStringAsync(this LucidCache cache, string key, CancellationToken token = default(CancellationToken))
        {
            var data = await cache.GetAsync(key, token);

            if (data == null)
            {
                return(null);
            }
            return(Encoding.UTF8.GetString(data, 0, data.Length));
        }
Esempio n. 2
0
        /// <summary>
        /// Gets a string from the specified cache with the specified key.
        /// </summary>
        /// <param name="cache">The cache in which to store the data.</param>
        /// <param name="key">The key to get the stored data for.</param>
        /// <returns>The string value from the stored cache key.</returns>
        public static string GetString(this LucidCache cache, string key)
        {
            var data = cache.Get(key);

            if (data == null)
            {
                return(null);
            }
            return(Encoding.UTF8.GetString(data, 0, data.Length));
        }
Esempio n. 3
0
 /// <summary>
 /// Sets a string in the specified cache with the specified key.
 /// </summary>
 /// <param name="cache">The cache in which to store the data.</param>
 /// <param name="key">The key to store the data in.</param>
 /// <param name="value">The data to store in the cache.</param>
 /// <param name="options">The cache options for the entry.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="key"/> or <paramref name="value"/> is null.</exception>
 public static void SetString(this LucidCache cache, string key, string value, DistributedCacheEntryOptions options)
 {
     if (key == null)
     {
         throw new ArgumentNullException(nameof(key));
     }
     if (value == null)
     {
         throw new ArgumentNullException(nameof(value));
     }
     cache.Set(key, Encoding.UTF8.GetBytes(value), options);
 }
Esempio n. 4
0
 /// <summary>
 /// Asynchronously sets a string in the specified cache with the specified key.
 /// </summary>
 /// <param name="cache">The cache in which to store the data.</param>
 /// <param name="key">The key to store the data in.</param>
 /// <param name="value">The data to store in the cache.</param>
 /// <param name="options">The cache options for the entry.</param>
 /// <param name="token">Optional. A <see cref="CancellationToken" /> to cancel the operation.</param>
 /// <returns>A task that represents the asynchronous set operation.</returns>
 /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="key"/> or <paramref name="value"/> is null.</exception>
 public static Task SetStringAsync(this LucidCache cache, string key, string value, DistributedCacheEntryOptions options, CancellationToken token = default(CancellationToken))
 {
     if (key == null)
     {
         throw new ArgumentNullException(nameof(key));
     }
     if (value == null)
     {
         throw new ArgumentNullException(nameof(value));
     }
     return(cache.SetAsync(key, Encoding.UTF8.GetBytes(value), options, token));
 }
Esempio n. 5
0
        /// <summary>
        /// Asynchronously sets a sequence of bytes in the specified cache with the specified key.
        /// </summary>
        /// <param name="cache">The cache in which to store the data.</param>
        /// <param name="key">The key to store the data in.</param>
        /// <param name="value">The data to store in the cache.</param>
        /// <param name="token">Optional. A <see cref="CancellationToken" /> to cancel the operation.</param>
        /// <returns>A task that represents the asynchronous set operation.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="key"/> or <paramref name="value"/> is null.</exception>
        public static Task SetAsync(this LucidCache cache, string key, byte[] value, CancellationToken token = default(CancellationToken))
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            return(cache.SetAsync(key, value, new DistributedCacheEntryOptions(), token));
        }
Esempio n. 6
0
        /// <summary>
        /// Sets a sequence of bytes in the specified cache with the specified key.
        /// </summary>
        /// <param name="cache">The cache in which to store the data.</param>
        /// <param name="key">The key to store the data in.</param>
        /// <param name="value">The data to store in the cache.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="key"/> or <paramref name="value"/> is null.</exception>
        public static void Set(this LucidCache cache, string key, byte[] value)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            cache.Set(key, value, new DistributedCacheEntryOptions());
        }
Esempio n. 7
0
 /// <summary>
 /// Asynchronously sets a string in the specified cache with the specified key.
 /// </summary>
 /// <param name="cache">The cache in which to store the data.</param>
 /// <param name="key">The key to store the data in.</param>
 /// <param name="value">The data to store in the cache.</param>
 /// <param name="token">Optional. A <see cref="CancellationToken" /> to cancel the operation.</param>
 /// <returns>A task that represents the asynchronous set operation.</returns>
 /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="key"/> or <paramref name="value"/> is null.</exception>
 public static Task SetStringAsync(this LucidCache cache, string key, string value, CancellationToken token = default(CancellationToken))
 {
     return(cache.SetStringAsync(key, value, new DistributedCacheEntryOptions(), token));
 }
Esempio n. 8
0
 /// <summary>
 /// Sets a string in the specified cache with the specified key.
 /// </summary>
 /// <param name="cache">The cache in which to store the data.</param>
 /// <param name="key">The key to store the data in.</param>
 /// <param name="value">The data to store in the cache.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="key"/> or <paramref name="value"/> is null.</exception>
 public static void SetString(this LucidCache cache, string key, string value)
 {
     cache.SetString(key, value, new DistributedCacheEntryOptions());
 }