示例#1
0
        /// <summary>A DelayedQuery&lt;TResult&gt; extension method that future value.</summary>
        /// <typeparam name="TResult">Type of the result.</typeparam>
        /// <param name="query">The query to act on.</param>
        /// <returns>A FutureQueryValue&lt;TResult,TResult&gt;</returns>
        public static QueryFutureValue <TResult> FutureValue <TResult>(this QueryDelayed <TResult> query)
        {
            var objectQuery = query.Source.GetObjectQuery();
            var futureBatch = QueryFutureManager.AddOrGetBatch(objectQuery.Context);
            var futureQuery = new QueryFutureValue <TResult>(futureBatch, objectQuery);

            futureBatch.Queries.Add(futureQuery);

            return(futureQuery);
        }
示例#2
0
        /// <summary>
        ///     Return the result of the <paramref name="query" /> from the cache. If the query is not cached
        ///     yet, the query is materialized and cached before being returned.
        /// </summary>
        /// <typeparam name="T">Generic type parameter.</typeparam>
        /// <param name="query">The query to cache in the QueryCacheManager.</param>
        /// <param name="absoluteExpiration">The fixed date and time at which the cache entry will expire.</param>
        /// <param name="tags">
        ///     A variable-length parameters list containing tag to use for the cache
        ///     key and expiration.
        /// </param>
        /// <returns>The result of the query.</returns>
        public static T FromCache <T>(this QueryDelayed <T> query, DateTimeOffset absoluteExpiration, params string[] tags)
        {
            var key = QueryCacheManager.GetCacheKey(query, tags);

            var item = QueryCacheManager.Cache.Get(key);

            if (item == null)
            {
                item = query.Execute();
                QueryCacheManager.Cache.AddOrGetExisting(key, item, absoluteExpiration);
                QueryCacheManager.AddCacheTag(key, tags);
            }

            return((T)item);
        }
示例#3
0
        /// <summary>
        ///     Return the result of the <paramref name="query" /> from the cache. If the query is not cached
        ///     yet, the query is materialized and cached before being returned.
        /// </summary>
        /// <typeparam name="T">The generic type of the query.</typeparam>
        /// <param name="query">The query to cache in the QueryCacheManager.</param>
        /// <param name="policy">The policy to use to cache the query.</param>
        /// <param name="tags">
        ///     A variable-length parameters list containing tag to use for the cache
        ///     key and expiration.
        /// </param>
        /// <returns>The result of the query.</returns>
        public static T FromCache <T>(this QueryDelayed <T> query, CacheItemPolicy policy, params string[] tags)
        {
            var key = QueryCacheManager.GetCacheKey(query, tags);

            var item = QueryCacheManager.Cache.Get(key);

            if (item == null)
            {
                item = query.Execute();
                QueryCacheManager.Cache.AddOrGetExisting(key, item, policy);
                QueryCacheManager.AddCacheTag(key, tags);
            }

            return((T)item);
        }
示例#4
0
 /// <summary>
 ///     Return the result of the <paramref name="query" /> from the cache. If the query is not cached
 ///     yet, the query is materialized asynchronously and cached before being returned.
 /// </summary>
 /// <typeparam name="T">Generic type parameter.</typeparam>
 /// <param name="query">The query to cache in the QueryCacheManager.</param>
 /// <param name="tags">
 ///     A variable-length parameters list containing tag to use for the cache
 ///     key and expiration.
 /// </param>
 /// <returns>The result of the query.</returns>
 public static async Task <T> FromCacheAsync <T>(this QueryDelayed <T> query, params string[] tags)
 {
     return(await query.FromCacheAsync(QueryCacheManager.DefaultCacheItemPolicy, tags));
 }
示例#5
0
 /// <summary>
 ///     Return the result of the <paramref name="query" /> from the cache. If the query is not cached
 ///     yet, the query is materialized and cached before being returned.
 /// </summary>
 /// <typeparam name="T">Generic type parameter.</typeparam>
 /// <param name="query">The query to cache in the QueryCacheManager.</param>
 /// <param name="tags">
 ///     A variable-length parameters list containing tag to use for the cache
 ///     key and expiration.
 /// </param>
 /// <returns>The result of the query.</returns>
 public static T FromCache <T>(this QueryDelayed <T> query, params string[] tags)
 {
     return(query.FromCache(QueryCacheManager.DefaultCacheItemPolicy, tags));
 }
示例#6
0
 /// <summary>Gets cache key used to cache or retrieve query from the QueryCacheManager.</summary>
 /// <typeparam name="T">Generic type parameter.</typeparam>
 /// <param name="query">The query to cache or retrieve from the QueryCacheManager.</param>
 /// <param name="tags">A variable-length parameters list containing tag to create the cache key.</param>
 /// <returns>The cache key used to cache or retrieve query from the QueryCacheManager.</returns>
 public static string GetCacheKey <T>(QueryDelayed <T> query, string[] tags)
 {
     return(CachePrefix + string.Join(";", tags) + query.Source);
 }