Exemple #1
0
        private CacheOperationContext GetOperationContext(
            CacheOperation operation, MethodInfo method, Object[] args, Object target, Type targetType)
        {
            CacheOperationMetadata metadata = GetCacheOperationMetadata(operation, method, targetType);

            return(new CacheOperationContext(metadata, args, target));
        }
Exemple #2
0
 public CacheOperationContext(CacheOperationMetadata metadata, object[] args, object target)
 {
     this.Metadata   = metadata;
     this.Args       = args;
     this.Target     = target;
     this.Caches     = GetCaches(this, Metadata.CacheResolver);
     this.CacheNames = this.Caches?.Select(it => it.Name).ToList();
 }
Exemple #3
0
        public CacheOperationMetadata GetCacheOperationMetadata(CacheOperation operation, MethodInfo method, Type targetType)
        {
            var cacheKey = new CacheOperationCacheKey(operation, method, targetType);

            this.metadataCaches.TryGetValue(cacheKey, out var metadata);
            if (metadata == null)
            {
                IKeyGenerator keyGenerator;
                var           keyGeneratorName = operation.KeyGenerator;
                if (keyGeneratorName.HasText())
                {
                    keyGenerator = this._serviceProvider.GetServiceByName <IKeyGenerator>(keyGeneratorName);
                }
                else
                {
                    keyGenerator = new SimpleKeyGenerator();
                }

                ICacheResolver cacheResolver;
                var            cacheResolverName = operation.CacheResolver;
                if (cacheResolverName.HasText())
                {
                    cacheResolver = this._serviceProvider.GetServiceByName <ICacheResolver>(cacheResolverName);
                }
                else if (operation.CacheManager.HasText())
                {
                    ICacheManager cacheManager =
                        this._serviceProvider.GetServiceByName <ICacheManager>(operation.CacheManager);

                    SbAssert.NotNull(cacheManager, "cacheManager:" + operation.CacheManager + " Not Exist");

                    cacheResolver = new SimpleCacheResolver(cacheManager);
                }
                else
                {
                    cacheResolver = new SimpleCacheResolver();
                }

                metadata = new CacheOperationMetadata(operation, method, targetType, keyGenerator, cacheResolver);
            }

            return(metadata);
        }