Example #1
0
        private static object GetData(DataRuleSetting dataRuleSetting, IContentQuery <TextContent> contentQuery)
        {
            if (dataRuleSetting.CachingDuration > 0)
            {
                var policy = new CacheItemPolicy()
                {
                    SlidingExpiration = TimeSpan.FromSeconds(dataRuleSetting.CachingDuration)
                };
                switch (dataRuleSetting.TakeOperation)
                {
                case TakeOperation.First:
                    var lazyFirst = contentQuery.LazyFirstOrDefault();
                    return(GetCacheData(dataRuleSetting.TakeOperation, contentQuery, policy, () => lazyFirst.Value));

                case TakeOperation.Count:
                    var lazyCount = contentQuery.LazyCount();
                    return(GetCacheData(dataRuleSetting.TakeOperation, contentQuery, policy, () => lazyCount.Value));

                case TakeOperation.List:
                default:
                    return(GetCacheData(dataRuleSetting.TakeOperation, contentQuery, policy, () => contentQuery.ToArray()));
                }
            }
            else
            {
                switch (dataRuleSetting.TakeOperation)
                {
                case TakeOperation.First:
                    return(contentQuery.FirstOrDefault());

                case TakeOperation.Count:
                    return(contentQuery.Count());

                case TakeOperation.List:
                default:
                    return(contentQuery.ToArray());
                }
            }
        }
Example #2
0
 private static object GetData(DataRuleSetting dataRuleSetting, IContentQuery<TextContent> contentQuery)
 {
     if (dataRuleSetting.CachingDuration > 0)
     {
         var policy = new CacheItemPolicy() { SlidingExpiration = TimeSpan.FromSeconds(dataRuleSetting.CachingDuration) };
         switch (dataRuleSetting.TakeOperation)
         {
             case TakeOperation.First:
                 var lazyFirst = contentQuery.LazyFirstOrDefault();
                 return GetCacheData(dataRuleSetting.TakeOperation, contentQuery, policy, () => lazyFirst.Value);
             case TakeOperation.Count:
                 var lazyCount = contentQuery.LazyCount();
                 return GetCacheData(dataRuleSetting.TakeOperation, contentQuery, policy, () => lazyCount.Value);
             case TakeOperation.List:
             default:
                 return GetCacheData(dataRuleSetting.TakeOperation, contentQuery, policy, () => contentQuery.ToArray());
         }
     }
     else
     {
         switch (dataRuleSetting.TakeOperation)
         {
             case TakeOperation.First:
                 return contentQuery.FirstOrDefault();
             case TakeOperation.Count:
                 return contentQuery.Count();
             case TakeOperation.List:
             default:
                 return contentQuery.ToArray();
         }
     }
 }