public RedisRepository(string connectionString) { CacheManager = new RedisCacheManager(connectionString, errorRetryCount: 3, errorRetryInterval: TimeSpan.FromMilliseconds(500)); CacheKeyGenerator = new VersionedCacheKeyGenerator(); _cache = new Cache <T>(CacheManager, CacheKeyGenerator); }
public override async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) { await base.OnResultExecutionAsync(context, next); bool isCacheable = context.Result is StatusCodeResult actionResult ? IsCacheableStatusCode(actionResult.StatusCode) : IsCacheableStatusCode(context.HttpContext.Response?.StatusCode); if (!isCacheable) { return; } IServiceProvider serviceProvider = context.HttpContext.RequestServices; IApiCacheOutput cache = serviceProvider.GetRequiredService(typeof(IApiCacheOutput)) as IApiCacheOutput; CacheKeyGeneratorFactory cacheKeyGeneratorFactory = serviceProvider.GetRequiredService(typeof(CacheKeyGeneratorFactory)) as CacheKeyGeneratorFactory; ICacheKeyGenerator cacheKeyGenerator = cacheKeyGeneratorFactory.GetCacheKeyGenerator(cacheKeyGeneratorType); string controllerName = this.controller ?? (context.ActionDescriptor as ControllerActionDescriptor)?.ControllerTypeInfo.FullName; string baseCacheKey = cacheKeyGenerator.MakeBaseCacheKey(controllerName, this.methodName); await cache.RemoveStartsWithAsync(baseCacheKey); }
public OutputCacheMiddlewareRealCacheTests() { _loggerFactory = new Mock <IOcelotLoggerFactory>(); _logger = new Mock <IOcelotLogger>(); _loggerFactory.Setup(x => x.CreateLogger <OutputCacheMiddleware>()).Returns(_logger.Object); _mockOptions = new Mock <IOptions <OcelotEasyCachingOptions> >(); _cacheKeyGenerator = new CacheKeyGenerator(); _mockOptions.Setup(x => x.Value).Returns(new OcelotEasyCachingOptions() { EnableHybrid = false, ProviderName = "m1", }); IServiceCollection services = new ServiceCollection(); services.AddEasyCaching(x => x.UseInMemory(options => options.MaxRdSecond = 0, "m1")); IServiceProvider serviceProvider = services.BuildServiceProvider(); var factory = serviceProvider.GetService <IEasyCachingProviderFactory>(); _ocelotCache = new OcelotEasyCachingCache <CachedResponse>(_mockOptions.Object, factory, null); _downstreamContext = new DownstreamContext(new DefaultHttpContext()); _downstreamContext.DownstreamRequest = new Request.Middleware.DownstreamRequest(new HttpRequestMessage(HttpMethod.Get, "https://some.url/blah?abcd=123")); _next = context => Task.CompletedTask; _middleware = new OutputCacheMiddleware(_next, _loggerFactory.Object, _ocelotCache, _cacheKeyGenerator); }
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { await base.OnActionExecutionAsync(context, next); if ( context.HttpContext.Response != null && !( context.HttpContext.Response.StatusCode >= (int)HttpStatusCode.OK && context.HttpContext.Response.StatusCode < (int)HttpStatusCode.Ambiguous ) ) { return; } IServiceProvider serviceProvider = context.HttpContext.RequestServices; IApiOutputCache cache = serviceProvider.GetService(typeof(IApiOutputCache)) as IApiOutputCache; ICacheKeyGenerator cacheKeyGenerator = serviceProvider.GetService(typeof(ICacheKeyGenerator)) as ICacheKeyGenerator; if (cache != null && cacheKeyGenerator != null) { string controllerName = this.controller ?? (context.ActionDescriptor as ControllerActionDescriptor)?.ControllerTypeInfo.FullName; string baseCachekey = cacheKeyGenerator.MakeBaseCachekey(controllerName, this.methodName); await cache.RemoveStartsWithAsync(baseCachekey); } }
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { await base.OnActionExecutionAsync(context, next); if ( context.HttpContext.Response != null && !( context.HttpContext.Response.StatusCode >= (int)HttpStatusCode.OK && context.HttpContext.Response.StatusCode < (int)HttpStatusCode.Ambiguous ) ) { return; } IServiceProvider serviceProvider = context.HttpContext.RequestServices; IApiCacheOutput cache = serviceProvider.GetRequiredService(typeof(IApiCacheOutput)) as IApiCacheOutput; CacheKeyGeneratorFactory cacheKeyGeneratorFactory = serviceProvider.GetRequiredService(typeof(CacheKeyGeneratorFactory)) as CacheKeyGeneratorFactory; ICacheKeyGenerator cacheKeyGenerator = cacheKeyGeneratorFactory.GetCacheKeyGenerator(cacheKeyGeneratorType); string controllerName = this.controller ?? (context.ActionDescriptor as ControllerActionDescriptor)?.ControllerTypeInfo.FullName; string baseCacheKey = cacheKeyGenerator.MakeBaseCacheKey(controllerName, this.methodName); string key = IncludeActionParameters(context, baseCacheKey, actionParameters); await cache.RemoveStartsWithAsync(key); }
public ICacheKeyGenerator GetCacheKeyGenerator(Type cacheKeyGeneratorType) { Type generatorType = cacheKeyGeneratorType ?? typeof(ICacheKeyGenerator); ICacheKeyGenerator generator = serviceProvider.GetService(generatorType) as ICacheKeyGenerator; return(generator ?? new DefaultCacheKeyGenerator()); }
public AppPrincipalFactory(INetworkInformation networkInformation, ISecureCache claimsCache, ICacheKeyGenerator cacheKeyGenerator, IContainerResolve container, IApplicationContext applicationContext) { NetworkInformation = networkInformation; ClaimsCache = claimsCache; CacheKeyGenerator = cacheKeyGenerator; Container = container; ApplicationContext = applicationContext; }
public CacheAttributeCallHandler(IUnityContainer container, string cacheName) { _cacheName = cacheName; _container = container; _cache = string.IsNullOrWhiteSpace(cacheName) ? container.Resolve <ICache>() : container.Resolve <ICache>(cacheName); _keyGenerator = container.Resolve <ICacheKeyGenerator>(); }
public CacheHelper(IOcelotCache <CachedResponse> outputCache, ICacheKeyGenerator cacheGenerator, ILogger <CacheHelper> logger) { _outputCache = outputCache; _cacheGenerator = cacheGenerator; _logger = logger; }
public CacheAttributeCallHandler(IUnityContainer container, string cacheName) { _cacheName = cacheName; _container = container; _cache = string.IsNullOrWhiteSpace(cacheName) ? container.Resolve<ICache>() : container.Resolve<ICache>(cacheName); _keyGenerator = container.Resolve<ICacheKeyGenerator>(); }
/// <inheritdoc cref="CacheKeyGeneratedEventData"/> public void CacheKeyGenerated(FilterContext filterContext, string key, ICacheKeyGenerator keyGenerator, ResponseCachingContext context) { if (DiagnosticSource != null && DiagnosticSource.IsEnabled(CacheKeyGeneratedEventData.EventName)) { DiagnosticSource.Write(CacheKeyGeneratedEventData.EventName, new CacheKeyGeneratedEventData(filterContext, key, keyGenerator, context)); } }
public KillOutOfDateMostRecentItemsJob(IProvideCacheSettings cacheSettings, ICacheManager cacheManager, ICacheKeyGenerator cacheKeyGenerator) { logger = LogManager.GetLogger(GetType()); this.cacheSettings = cacheSettings; this.cacheManager = cacheManager; this.cacheKeyGenerator = cacheKeyGenerator; }
public DataKeyCache(ICacheKeyGenerator cacheKeyGenerator, IDistributedCache distributedCache, ICacheValueConverter cacheValueConverter, IDistributedCacheEntryOptionsFactory distributedCacheEntryOptionsFactory) { _cacheKeyGenerator = cacheKeyGenerator; _distributedCache = distributedCache; _cacheValueConverter = cacheValueConverter; _distributedCacheEntryOptionsFactory = distributedCacheEntryOptionsFactory; }
public ConstructionTimerEnd( ICacheKeyGenerator cacheKeyGenerator, Config.DebugSettings debugSettings, ILog log) { _cacheKeyGenerator = cacheKeyGenerator; _debugSettings = debugSettings; _log = log; }
public CacheKeyGeneratorTests() { _cacheKeyGenerator = new CacheKeyGenerator(); _cacheKeyGenerator = new CacheKeyGenerator(); _downstreamContext = new DownstreamContext(new DefaultHttpContext()) { DownstreamRequest = new Ocelot.Request.Middleware.DownstreamRequest(new HttpRequestMessage(HttpMethod.Get, "https://some.url/blah?abcd=123")) }; }
public CachingBehavior( ICacheProvider cacheProvider, ICacheKeyGenerator cacheKeyGenerator, ICacheRegionNameGenerator cacheRegionNameGenerator) { _cacheProvider = cacheProvider; _cacheKeyGenerator = cacheKeyGenerator; _cacheRegionNameGenerator = cacheRegionNameGenerator; }
/// <summary> /// Creates a new CacheKeyGenerator, that relies on a IServiceConsumptionOptions class, not requiring an HttpActionContext /// </summary> /// <exception cref="ArgumentNullException">If serviceOptions are null</exception> /// <param name="serviceOptions"></param> public GenericCacheKeyGenerator(IServiceConsumptionOptions serviceOptions) { if (serviceOptions == null) { throw new ArgumentNullException("serviceOptions"); } _serviceOptions = serviceOptions; _specificCacheKeyGenerator = new CustomCacheKeyGenerator(); }
public CacheBuilder(IServiceCollection serviceCollection, ICacheKeyGenerator cacheKeyGenerator, string configurationKey) { if (string.IsNullOrWhiteSpace(configurationKey)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(configurationKey)); } _serviceCollection = serviceCollection ?? throw new ArgumentNullException(nameof(serviceCollection)); _cacheKeyGenerator = cacheKeyGenerator ?? throw new ArgumentNullException(nameof(cacheKeyGenerator)); _configurationKey = configurationKey; }
public OutputCacheMiddleware(OcelotRequestDelegate next, IOcelotLoggerFactory loggerFactory, IOcelotCache <CachedResponse> outputCache, ICacheKeyGenerator cacheGeneratot) : base(loggerFactory.CreateLogger <OutputCacheMiddleware>()) { _next = next; _outputCache = outputCache; _cacheGeneratot = cacheGeneratot; }
public ConstructionTimerStart( ICacheKeyGenerator cacheKeyGenerator, ILog log, Config.DebugSettings debugSettings) { _cacheKeyGenerator = cacheKeyGenerator; _log = log; _debugSettings = debugSettings; Name = "ConstructionTimerStart"; }
public ProfiledConstructionTimerStart( ICacheKeyGenerator cacheKeyGenerator, Config.DebugSettings debugSettings, AbstractObjectConstructionTask inner) { _cacheKeyGenerator = cacheKeyGenerator; _debugSettings = debugSettings; Name = "ConstructionTimerStart"; _inner = inner; }
public OutputCacheMiddlewareTests() { _cache = new Mock <IOcelotCache <CachedResponse> >(); _downstreamContext = new DownstreamContext(new DefaultHttpContext()); _loggerFactory = new Mock <IOcelotLoggerFactory>(); _logger = new Mock <IOcelotLogger>(); _cacheKeyGenerator = new CacheKeyGenerator(); _loggerFactory.Setup(x => x.CreateLogger <OutputCacheMiddleware>()).Returns(_logger.Object); _next = context => Task.CompletedTask; _downstreamContext.DownstreamRequest = new Ocelot.Request.Middleware.DownstreamRequest(new HttpRequestMessage(HttpMethod.Get, "https://some.url/blah?abcd=123")); }
public KeyManagementServiceCache( IKeyManagementService keyManagementService, IDistributedCache distributedCache, ICacheKeyGenerator cacheKeyGenerator, ICacheValueConverter cacheValueConverter) { _distributedCache = distributedCache; _cacheKeyGenerator = cacheKeyGenerator; _cacheValueConverter = cacheValueConverter; _keyManagementService = keyManagementService; }
public SiteAvailableProvider(IRepository<LocalEducationAgencyAdministration> repository, ICacheProvider cacheProvider, IConfigValueProvider configValueProvider, ICurrentUserClaimInterrogator currentUserClaimInterrogator, ICacheKeyGenerator cacheKeyGenerator) { this.repository = repository; this.cacheProvider = cacheProvider; this.configValueProvider = configValueProvider; this.currentUserClaimInterrogator = currentUserClaimInterrogator; this.cacheKeyGenerator = cacheKeyGenerator; }
/// <summary> /// /// </summary> /// <param name="nancyBootstrapper"></param> /// <param name="routeResolver"></param> /// <param name="pipeline"></param> /// <param name="cacheKeyGenerator"></param> /// <param name="cacheStore"></param> public static void Enable(INancyBootstrapper nancyBootstrapper, IRouteResolver routeResolver, IPipelines pipeline, ICacheKeyGenerator cacheKeyGenerator, ICacheStore cacheStore) { if (_enabled) return; _enabled = true; _cacheKeyGenerator = cacheKeyGenerator; _cacheStore = cacheStore; _nancyBootstrapper = nancyBootstrapper; _routeResolver = routeResolver; pipeline.BeforeRequest.AddItemToStartOfPipeline(CheckCache); pipeline.AfterRequest.AddItemToEndOfPipeline(SetCache); }
public ICacheKeyGenerator GetCacheKeyGenerator(Type cacheKeyGeneratorType) { if (cacheKeyGeneratorType != null && !typeof(ICacheKeyGenerator).IsAssignableFrom(cacheKeyGeneratorType)) { throw new ArgumentException(nameof(cacheKeyGeneratorType)); } Type generatorType = cacheKeyGeneratorType ?? typeof(ICacheKeyGenerator); ICacheKeyGenerator generator = serviceProvider.GetService(generatorType) as ICacheKeyGenerator; return(generator ?? new DefaultCacheKeyGenerator()); }
/// <summary> /// /// </summary> /// <param name="nancyBootstrapper"></param> /// <param name="routeResolver"></param> /// <param name="pipeline"></param> /// <param name="cacheKeyGenerator"></param> /// <param name="cacheStore"></param> public static void Enable(INancyBootstrapper nancyBootstrapper, IRouteResolver routeResolver, IPipelines pipeline, ICacheKeyGenerator cacheKeyGenerator, ICacheStore cacheStore) { if (_enabled) { return; } _enabled = true; _cacheKeyGenerator = cacheKeyGenerator; _cacheStore = cacheStore; _nancyBootstrapper = nancyBootstrapper; _routeResolver = routeResolver; pipeline.BeforeRequest.AddItemToStartOfPipeline(CheckCache); pipeline.AfterRequest.AddItemToEndOfPipeline(SetCache); }
/// <summary> /// Initializes a new instance of the <see cref="DynamicStyleBundle"/> class. /// </summary> /// <param name="virtualPath">The virtual path.</param> /// <param name="cdnPath">The cdn path.</param> /// <param name="cacheKeyGenerator">The implementation of cache key generator.</param> /// <param name="cacheToggleProvider">The implementation of cache toggle provider.</param> /// <param name="transforms">The bundle transformers.</param> public DynamicStyleBundle(string virtualPath, string cdnPath, ICacheKeyGenerator cacheKeyGenerator, ICacheToggleProvider cacheToggleProvider, params IBundleTransform[] transforms) : base(virtualPath, cdnPath, transforms) { if (cacheKeyGenerator == null) { throw new ArgumentNullException("cacheKeyGenerator"); } if (cacheToggleProvider == null) { throw new ArgumentNullException("cacheToggleProvider"); } _cacheKeyGenerator = cacheKeyGenerator; _cacheToggleProvider = cacheToggleProvider; }
public static void UseAwsKeyManagementServiceSerializerWithCache(this IReceiveEndpointConfigurator configurator, IKeyManagementService amazonKeyManagementService, IEncryptionContextBuilder encryptionContextBuilder, string kmsKeyId, IDistributedCache distributedCache, ICacheKeyGenerator cacheKeyGenerator, ICacheValueConverter cacheValueConverter) { var keyManagementServiceCache = new KeyManagementServiceCache(amazonKeyManagementService, distributedCache, cacheKeyGenerator, cacheValueConverter); configurator.UseAwsKeyManagementServiceSerializer(keyManagementServiceCache, encryptionContextBuilder, kmsKeyId); }
public static void UseAwsKeyManagementServiceSerializerWithCache(this IReceiveEndpointConfigurator configurator, IKeyManagementService amazonKeyManagementService, IEncryptionContextBuilder encryptionContextBuilder, string kmsKeyId, IDistributedCache distributedCache, ICacheKeyGenerator cacheKeyGenerator, ICacheValueConverter cacheValueConverter, IDistributedCacheEntryOptionsFactory distributedCacheEntryOptionsFactory) { var dataKeyCache = new DataKeyCache(cacheKeyGenerator, distributedCache, cacheValueConverter, distributedCacheEntryOptionsFactory); var decryptKeyCache = new DecryptKeyCache(cacheKeyGenerator, distributedCache, distributedCacheEntryOptionsFactory); configurator.UseAwsKeyManagementServiceSerializerWithCache(amazonKeyManagementService, encryptionContextBuilder, kmsKeyId, dataKeyCache, decryptKeyCache); }
public OutputCacheMiddlewareRealCacheTests() { _loggerFactory = new Mock <IOcelotLoggerFactory>(); _logger = new Mock <IOcelotLogger>(); _loggerFactory.Setup(x => x.CreateLogger <OutputCacheMiddleware>()).Returns(_logger.Object); var cacheManagerOutputCache = CacheFactory.Build <CachedResponse>("OcelotOutputCache", x => { x.WithDictionaryHandle(); }); _cacheManager = new OcelotCacheManagerCache <CachedResponse>(cacheManagerOutputCache); _cacheKeyGenerator = new CacheKeyGenerator(); _downstreamContext = new DownstreamContext(new DefaultHttpContext()); _downstreamContext.DownstreamRequest = new Ocelot.Request.Middleware.DownstreamRequest(new HttpRequestMessage(HttpMethod.Get, "https://some.url/blah?abcd=123")); _next = context => Task.CompletedTask; _middleware = new OutputCacheMiddleware(_next, _loggerFactory.Object, _cacheManager, _cacheKeyGenerator); }
public CacheOptions(string methodToInterceptKey, ITypedCacheStorage <TData> storage, ICacheKeyGenerator cachedItemKeyGenerator, string region) { if (string.IsNullOrWhiteSpace(methodToInterceptKey)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(methodToInterceptKey)); } if (string.IsNullOrWhiteSpace(region)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(region)); } MethodToInterceptKey = methodToInterceptKey; CachedItemKeyGenerator = cachedItemKeyGenerator ?? throw new ArgumentNullException(nameof(cachedItemKeyGenerator)); Region = region; Storage = storage ?? throw new ArgumentNullException(nameof(storage)); }
public CacheInterceptor(ICacheProvider[] cacheProviders, ICacheKeyGenerator cacheKeyGenerator, IConfigValueProvider configValueProvider, IServiceLocator serviceLocator, ISerializer serializer) { this.cacheProviders = cacheProviders; this.cacheKeyGenerator = cacheKeyGenerator; this.serviceLocator = serviceLocator; this.serializer = serializer; cacheExpiryMinutes = Convert.ToInt32(configValueProvider.GetValue("CacheInterceptor.SlidingExpiration")); //The first cache provider is the default. defaultCacheProvider = cacheProviders.First(); // Default to 5 minutes sliding expiration if (cacheExpiryMinutes == 0) cacheExpiryMinutes = 5; cacheEnabled = Convert.ToBoolean(configValueProvider.GetValue("CacheInterceptor.Enabled")); }
/// <summary> /// <inheritdoc cref="ResponseCachingContext"/> /// </summary> /// <param name="metadatas">Action端点的 <see cref="EndpointMetadataCollection"/></param> /// <param name="cacheKeyGenerator"></param> /// <param name="responseCache"></param> /// <param name="cacheDeterminer"></param> /// <param name="options"></param> /// <param name="interceptorAggregator"></param> /// <param name="dumpStreamCapacity"></param> public ResponseCachingContext(EndpointMetadataCollection metadatas, ICacheKeyGenerator cacheKeyGenerator, IResponseCache responseCache, IResponseCacheDeterminer cacheDeterminer, ResponseCachingOptions options, InterceptorAggregator interceptorAggregator, int dumpStreamCapacity) { if (metadatas is null) { throw new ArgumentNullException(nameof(metadatas)); } MaxCacheableResponseLength = Checks.ThrowIfMaxCacheableResponseLengthTooSmall(Metadata <IMaxCacheableResponseLengthMetadata>()?.MaxCacheableResponseLength ?? options.MaxCacheableResponseLength); MaxCacheKeyLength = options.MaxCacheKeyLength; KeyGenerator = cacheKeyGenerator ?? throw new ArgumentNullException(nameof(cacheKeyGenerator)); ResponseCache = responseCache ?? throw new ArgumentNullException(nameof(responseCache)); CacheDeterminer = cacheDeterminer ?? throw new ArgumentNullException(nameof(cacheDeterminer)); Duration = Checks.ThrowIfDurationTooSmall(RequiredMetadata <IResponseDurationMetadata>().Duration); DurationMilliseconds = Duration * 1000; var executingLockMetadata = Metadata <IExecutingLockMetadata>(); LockMillisecondsTimeout = Checks.ThrowIfLockMillisecondsTimeoutInvalid(executingLockMetadata?.LockMillisecondsTimeout ?? options.DefaultLockMillisecondsTimeout).Value; Interceptors = interceptorAggregator; DumpStreamCapacity = Checks.ThrowIfDumpStreamInitialCapacityTooSmall(dumpStreamCapacity, nameof(dumpStreamCapacity)); OnCannotExecutionThroughLock = options.OnCannotExecutionThroughLock ?? DefaultExecutionLockTimeoutFallback.SetStatus429; OnExecutionLockTimeout = executingLockMetadata?.OnExecutionLockTimeout ?? options.OnExecutionLockTimeoutFallback ?? DefaultExecutionLockTimeoutFallback.SetStatus429; TMetadata?Metadata <TMetadata>() where TMetadata : class => metadatas.GetMetadata <TMetadata>();
/// <summary> /// Enables Nancy.LightningCache using the supplied parameters and CacheStore type /// </summary> /// <param name="bootstrapper"></param> /// <param name="routeResolver"> </param> /// <param name="pipelines"></param> /// <param name="cacheKeyGenerator"></param> /// <param name="cacheStore"> </param> public static void EnableLightningCache(this INancyBootstrapper bootstrapper, IRouteResolver routeResolver, IPipelines pipelines, ICacheKeyGenerator cacheKeyGenerator, ICacheStore cacheStore) { LightningCache.Enable(bootstrapper, routeResolver, pipelines, cacheKeyGenerator, cacheStore); }
public SystemMessageProvider(IRepository<LocalEducationAgencyAdministration> repository, ICacheKeyGenerator cacheKeyGenerator) { this.repository = repository; this.cacheKeyGenerator = cacheKeyGenerator; }
public CachingInterceptor() { _keyGenerator = new DefaultCacheKeyGenerator(); }
public CacheCheckTask(ICacheManager cacheManager, ICacheKeyGenerator cacheKeyGenerator) { CacheManager = cacheManager; CacheKeyGenerator = cacheKeyGenerator; Name = "CacheCheckTask"; }
/// <inheritdoc cref="CacheKeyGeneratedEventData"/> public CacheKeyGeneratedEventData(FilterContext filterContext, string key, ICacheKeyGenerator keyGenerator, ResponseCachingContext context) : base(context) { FilterContext = filterContext; Key = key; KeyGenerator = keyGenerator; }
/// <summary> /// /// </summary> /// <param name="nancyBootstrapper"></param> /// <param name="routeResolver"></param> /// <param name="pipelines"></param> /// <param name="cacheKeyGenerator"></param> public static void Enable(INancyBootstrapper nancyBootstrapper, IRouteResolver routeResolver, IPipelines pipelines, ICacheKeyGenerator cacheKeyGenerator) { Enable(nancyBootstrapper, routeResolver, pipelines, cacheKeyGenerator, new WebCacheStore()); }
public JsonCacheKeyGeneratorTests() { _generator = new JsonCacheKeyGenerator(); _referenceType = typeof(ReferenceMethods); }
protected void MockCacheKeyGenerator(string cacheKey) { suppliedCacheKey = cacheKey; cacheKeyGenerator = mocks.StrictMock<ICacheKeyGenerator>(); Expect.Call(cacheKeyGenerator.GenerateCacheKey(null, null)) .IgnoreArguments() .Return(suppliedCacheKey); }