コード例 #1
0
 public Result <TResponse> Execute(TQuery query) =>
 handler
 .Execute(query)
 .OnFailure(error => EventLogProvider.LogEvent(new EventLogInfo
 {
     EventCode        = "Error",
     EventDescription = error,
     EventType        = query.GetType().Name,
 }));
        public Result <TResponse> Execute(TQuery query)
        {
            if (!queryCacheSettings.IsEnabled)
            {
                return(handler.Execute(query));
            }

            if (!(handler is IQuerySyncCacheKeysCreator <TQuery, TResponse> cacheKeysCreator))
            {
                return(handler.Execute(query));
            }

            var cacheSettings = new CacheSettings(
                cacheMinutes: queryCacheSettings.CacheItemDuration.Minutes,
                useSlidingExpiration: true,
                cacheItemNameParts: cacheKeysCreator.ItemNameParts(query));

            return(cacheHelper.Cache(
                       (cs) =>
            {
                var result = handler.Execute(query);

                if (cs.Cached)
                {
                    cs.GetCacheDependency = () =>
                    {
                        string[] cacheKeys = cacheKeysCreator.DependencyKeys(query, result);

                        cacheKeyStore.AddDependencyOnKeys(cacheKeys);

                        return cacheHelper.GetCacheDependency(cacheKeys);
                    };
                }

                return result;
            },
                       cacheSettings));
        }