/// <summary> /// 创建一个标准缓存策略 /// </summary> /// <param name="context">请求上下文</param> /// <param name="token">缓存标示</param> /// <param name="provider">缓存策略提供程序</param> /// <param name="duration">缓存持续时间</param> /// <param name="enableClientCache">是否启用客户端缓存</param> /// <param name="localcacheVirtualPath">静态文件缓存虚拟路径</param> /// <param name="enableMemoryCache">是否启用内存缓存</param> public StandardCachePolicy(HttpContextBase context, CacheToken token, ICachePolicyProvider provider, TimeSpan duration, bool enableClientCache, string localcacheVirtualPath, bool enableMemoryCache) : base(context, token, provider) { if (context == null) { throw new ArgumentNullException("context"); } if (provider == null) { throw new ArgumentNullException("provider"); } Duration = duration; EnableClientCache = enableClientCache; if (localcacheVirtualPath != null) { var physicalPath = context.Server.MapPath(localcacheVirtualPath); CacheStorageProvider = new StaticFileCacheStorageProvider(physicalPath, enableMemoryCache); } else { CacheStorageProvider = new WebCacheStorageProvider(HttpRuntime.Cache); } }
public static IMethodFamilyConfigurationExpression For <T>(this ICachePolicyProvider <T> provider, Expression <Action <T> > expression) where T : class { var configuredMethod = new ExpressionConfiguredMethod <T>(expression); var policy = provider.RegisterMethodConfiguration(configuredMethod); return(new MethodFamilyConfigExpression(policy)); }
/// <summary> /// 创建一个标准缓存策略 /// </summary> /// <param name="context">请求上下文</param> /// <param name="token">缓存标示</param> /// <param name="provider">缓存策略提供程序</param> /// <param name="duration">缓存持续时间</param> /// <param name="enableClientCache">是否启用客户端缓存</param> /// <param name="localcacheVirtualPath">静态文件缓存虚拟路径</param> /// <param name="enableMemoryCache">是否启用内存缓存</param> public StandardCachePolicy( HttpContextBase context, CacheToken token, ICachePolicyProvider provider, TimeSpan duration, bool enableClientCache, string localcacheVirtualPath, bool enableMemoryCache ) : base( context, token, provider ) { if ( context == null ) throw new ArgumentNullException( "context" ); if ( provider == null ) throw new ArgumentNullException( "provider" ); Duration = duration; EnableClientCache = enableClientCache; if ( localcacheVirtualPath != null ) { var physicalPath = context.Server.MapPath( localcacheVirtualPath ); CacheStorageProvider = new StaticFileCacheStorageProvider( physicalPath, enableMemoryCache ); } else { CacheStorageProvider = new WebCacheStorageProvider( HttpRuntime.Cache ); } }
public AsyncLookupHandler(T implementation, ICachePolicyProvider <T> cachePolicyProvider, ICacheProvider <T> cache) { _implementation = implementation; _cachePolicyProvider = cachePolicyProvider; _cache = cache; _taskSyncronizer = new TaskSyncronizer(); }
public SleipnerCache(T implementation, ICacheProvider <T> cache) { _implementation = implementation; _cache = cache; CachePolicyProvider = new BasicConfigurationProvider <T>(); _proxyHandler = new SleipnerCacheProxyHandler <T>(_implementation, CachePolicyProvider, _cache); }
/// <summary> /// Initializes a new instance of the <see cref="InMemoryCacheProvider" /> class. /// </summary> /// <param name="cachePolicyProvider">The cache policy provider.</param> public InMemoryCacheProvider(ICachePolicyProvider cachePolicyProvider) { _cachePolicyProvider = cachePolicyProvider; _cache = MemoryCache.Default; _cacheKeys = new HashSet <string>(); _lockObject = new object(); _lockObjectsForKeys = new Dictionary <string, object>(); _lockObjectForCacheKeys = new object(); }
/// <summary> /// Registers an <see cref="Microsoft.Azure.Mobile.Server.Cache.ICachePolicyProvider"/> with the current <see cref="System.Web.Http.HttpConfiguration" />. /// </summary> /// <param name="config">The current <see cref="System.Web.Http.HttpConfiguration"/>.</param> /// <param name="provider">The instance to register.</param> public static void SetCachePolicyProvider(this HttpConfiguration config, ICachePolicyProvider provider) { if (config == null) { throw new ArgumentNullException("config"); } config.Properties[CachePolicyProviderKey] = provider; }
public SleipnerCacheProxyHandler(T implementation, ICachePolicyProvider <T> cachePolicyProvider, ICacheProvider <T> cache) { _implementation = implementation; _cachePolicyProvider = cachePolicyProvider; _cache = cache; _asyncLookupHandler = new AsyncLookupHandler <T>(_implementation, _cachePolicyProvider, _cache); _syncLookupHandler = new SyncLookupHandler <T>(_implementation, _cachePolicyProvider, _cache); _taskUpdateSyncronizer = new TaskSyncronizer(); }
public static ICachePolicyProvider GetCachePolicyProvider(this HttpConfiguration config) { if (config == null) { throw new ArgumentNullException("config"); } ICachePolicyProvider provider = config.Properties.GetValueOrDefault <ICachePolicyProvider>(CachePolicyProviderKey); return(provider); }
/// <summary> /// 将 CacheItem 对象从指定文件路径反序列化还原 /// </summary> /// <param name="provider">创建此 CacheItem 对象的 ICachePolicyProvider</param> /// <param name="filepath">文件路径</param> public static CacheItem DeserializeFrom(this ICachePolicyProvider provider, string filepath) { if (!File.Exists(filepath)) { return(null); } using (var stream = File.OpenRead(filepath)) { return(DeserializeFrom(provider, stream)); } }
public void GetCachePolicyProvider_ReturnsDefaultInstance() { // Arrange HttpConfiguration config = new HttpConfiguration(); // Act ICachePolicyProvider actual = config.GetCachePolicyProvider(); // Assert Assert.NotNull(actual); Assert.IsType <CachePolicyProvider>(actual); }
public void SetCachePolicyProvider_Roundtrips() { // Arrange CachePolicyProvider provider = new CachePolicyProvider(); HttpConfiguration config = new HttpConfiguration(); // Act config.SetCachePolicyProvider(provider); ICachePolicyProvider actual = config.GetCachePolicyProvider(); // Assert Assert.Same(provider, actual); }
public void SetCachePolicyProvider_ReturnsDefault_IfSetToNull() { // Arrange HttpConfiguration config = new HttpConfiguration(); // Act config.SetCachePolicyProvider(null); ICachePolicyProvider actual = config.GetCachePolicyProvider(); // Assert Assert.NotNull(actual); Assert.IsType <CachePolicyProvider>(actual); }
/// <summary> /// 创建一个标准缓存策略 /// </summary> /// <param name="context">请求上下文</param> /// <param name="token">缓存标示</param> /// <param name="provider">缓存策略提供程序</param> /// <param name="duration">缓存持续时间</param> /// <param name="enableClientCache">是否启用客户端缓存</param> /// <param name="storageProvider">缓存储存提供程序</param> public StandardCachePolicy( HttpContextBase context, CacheToken token, ICachePolicyProvider provider, TimeSpan duration, bool enableClientCache, ICacheStorageProvider storageProvider ) : base(context, token, provider) { if ( context == null ) throw new ArgumentNullException( "context" ); if ( provider == null ) throw new ArgumentNullException( "provider" ); Duration = duration; EnableClientCache = enableClientCache; CacheStorageProvider = storageProvider; }
private static void SetCachePolicy(ICachePolicyProvider provider, HttpRequestMessage request, HttpResponseMessage response, ITraceWriter tracer) { if (provider != null && response != null && IsCacheableMethod(request.Method) && !HasCachingHeaders(response)) { try { provider.SetCachePolicy(response); } catch (Exception ex) { string msg = RResources.CachePolicy_BadProvider.FormatForUser(provider.GetType().Name, ex.Message); tracer.Error(msg, ex, request, LogCategories.MessageHandlers); } } }
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) { if (actionExecutedContext == null) { throw new ArgumentNullException("actionExecutedContext"); } HttpConfiguration config = actionExecutedContext.ActionContext.ControllerContext.Configuration; ICachePolicyProvider provider = config.GetCachePolicyProvider(); HttpRequestMessage request = actionExecutedContext.Request; HttpResponseMessage response = actionExecutedContext.Response; SetCachePolicy(provider, request, response, config.Services.GetTraceWriter()); SetVersionHeader(response); }
/// <summary> /// 将 CacheItem 对象从指定流反序列化还原 /// </summary> /// <param name="provider">创建此 CacheItem 对象的 ICachePolicyProvider</param> /// <param name="stream">用于反序列化的读取流</param> public static CacheItem DeserializeFrom(this ICachePolicyProvider provider, Stream stream) { var fomatter = new BinaryFormatter(); CacheItem item; item = (CacheItem)fomatter.Deserialize(stream); if (item.Expiration < DateTime.UtcNow)//缓存已过期 { return(null); } item.Provider = provider; return(item); }
public SleipnerProxy(T realInstance, ICacheProvider <T> cacheProvider) { if (!typeof(T).IsInterface) { throw new ArgumentException("T must be an interface", "realInstance"); } var proxyType = CacheProxyGenerator.GetProxyType <T>(); T realInstance1 = realInstance; CachePolicyProvider = new BasicConfigurationProvider <T>(); IProxyHandler <T> proxyHandler = new ThrottledProxyHandler <T>(realInstance1, CachePolicyProvider, cacheProvider); Object = (T)Activator.CreateInstance(proxyType, realInstance1, proxyHandler); }
/// <summary> /// Gets the <see cref="Microsoft.Azure.Mobile.Server.Cache.ICachePolicyProvider"/> registered with the current <see cref="System.Web.Http.HttpConfiguration" />. /// </summary> /// <param name="config">The current <see cref="System.Web.Http.HttpConfiguration"/>.</param> /// <returns>The registered instance.</returns> public static ICachePolicyProvider GetCachePolicyProvider(this HttpConfiguration config) { if (config == null) { throw new ArgumentNullException("config"); } ICachePolicyProvider provider = null; if (!config.Properties.TryGetValue(CachePolicyProviderKey, out provider)) { provider = new CachePolicyProvider(); config.Properties[CachePolicyProviderKey] = provider; } return(provider); }
/// <summary> /// 创建一个标准缓存策略 /// </summary> /// <param name="context">请求上下文</param> /// <param name="token">缓存标示</param> /// <param name="provider">缓存策略提供程序</param> /// <param name="duration">缓存持续时间</param> /// <param name="enableClientCache">是否启用客户端缓存</param> /// <param name="storageProvider">缓存储存提供程序</param> public StandardCachePolicy(HttpContextBase context, CacheToken token, ICachePolicyProvider provider, TimeSpan duration, bool enableClientCache, ICacheStorageProvider storageProvider) : base(context, token, provider) { if (context == null) { throw new ArgumentNullException("context"); } if (provider == null) { throw new ArgumentNullException("provider"); } Duration = duration; EnableClientCache = enableClientCache; CacheStorageProvider = storageProvider; }
public MyCachePolicy(HttpContextBase context, CacheToken cacheToken, ICachePolicyProvider provider) : base(context, cacheToken, provider, TimeSpan.FromDays(1), true, "~/StaticCaches", true) { }
/// <summary> /// 创建一个标准缓存策略 /// </summary> /// <param name="context">请求上下文</param> /// <param name="token">缓存标示</param> /// <param name="provider">缓存策略提供程序</param> /// <param name="duration">缓存持续时间</param> /// <param name="enableClientCache">是否启用客户端缓存</param> public StandardCachePolicy(HttpContextBase context, CacheToken token, ICachePolicyProvider provider, TimeSpan duration, bool enableClientCache) : this(context, token, provider, duration, enableClientCache, new WebCacheStorageProvider()) { }
/// <summary> /// 创建一个标准缓存策略 /// </summary> /// <param name="context">请求上下文</param> /// <param name="token">缓存标示</param> /// <param name="provider">缓存策略提供程序</param> /// <param name="duration">缓存持续时间</param> /// <param name="enableClientCache">是否启用客户端缓存</param> public StandardCachePolicy( HttpContextBase context, CacheToken token, ICachePolicyProvider provider, TimeSpan duration, bool enableClientCache ) : this(context, token, provider, duration, enableClientCache, new WebCacheStorageProvider()) { }
/// <summary> /// 创建 MvcCachePolicyProviderWrapper 对象 /// </summary> /// <param name="provider">需要被包装的原始的 ICachePolicyProvider 对象</param> public MvcCachePolicyProviderWrapper(ICachePolicyProvider provider) { _provider = provider; }
/// <summary> /// Initializes a new instance of the <see cref="RedisCacheProvider" /> class. /// </summary> /// <param name="cachePolicyProvider">The cache policy provider.</param> /// <param name="connectionString">The redis connectionstring.</param> public RedisCacheProvider(ICachePolicyProvider cachePolicyProvider, string connectionString) { _cachePolicyProvider = cachePolicyProvider; _connectionString = connectionString; Connect(); }
public static IMethodFamilyConfigurationExpression DefaultIs <T>(this ICachePolicyProvider <T> provider) where T : class { var policy = provider.GetDefaultPolicy(); return(new MethodFamilyConfigExpression(policy)); }
/// <summary> /// /// </summary> /// <param name="connectionMultiplexer"></param> /// <param name="database"></param> public RedisCacheProvider(IConnectionMultiplexer connectionMultiplexer, IDatabase database, ICachePolicyProvider cachePolicyProvider) { _connection = connectionMultiplexer; _cacheDb = database; _cachePolicyProvider = cachePolicyProvider; }
public ThrottledProxyHandler(T realInstance, ICachePolicyProvider <T> cachePolicyProvider, ICacheProvider <T> cacheProvider) { _realInstance = realInstance; _cachePolicyProvider = cachePolicyProvider; _cacheProvider = cacheProvider; }
public MyCachePolicy( HttpContextBase context, CacheToken cacheToken, ICachePolicyProvider provider ) : base(context, cacheToken, provider, TimeSpan.FromDays( 1 ), true, "~/StaticCaches", true) { }
public static CachePolicy GetPolicy <T, TResult>(this ICachePolicyProvider <T> provider, Expression <Func <T, TResult> > expression) where T : class { var invocation = ProxiedMethodInvocationGenerator <T> .FromExpression(expression); return(provider.GetPolicy(invocation)); }
private static void SetCachePolicy(ICachePolicyProvider provider, HttpRequestMessage request, HttpResponseMessage response, ITraceWriter tracer) { if (provider != null && response != null && IsCacheableMethod(request.Method) && !HasCachingHeaders(response)) { try { provider.SetCachePolicy(response); } catch (Exception ex) { string msg = RResources.CachePolicy_BadProvider.FormatForUser(provider.GetType().Name, ex.Message); tracer.Error(msg, ex, request, LogCategories.MessageHandlers); } } }
/// <summary> /// 创建 MvcCachePolicyProviderWrapper 对象 /// </summary> /// <param name="provider">需要被包装的原始的 ICachePolicyProvider 对象</param> public MvcCachePolicyProviderWrapper( ICachePolicyProvider provider ) { _provider = provider; }
/// <summary> /// 创建 CachePolicy 实例 /// </summary> /// <param name="context">HTTP 上下文</param> /// <param name="token">缓存标识</param> /// <param name="provider">缓存策略提供程序</param> public CachePolicy(HttpContextBase context, CacheToken token, ICachePolicyProvider provider) { HttpContext = context; CacheToken = token; Provider = provider; }
/// <summary> /// Registers an <see cref="Microsoft.Azure.Mobile.Server.Cache.ICachePolicyProvider"/> with the current <see cref="System.Web.Http.HttpConfiguration" />. /// </summary> /// <param name="config">The current <see cref="System.Web.Http.HttpConfiguration"/>.</param> /// <param name="provider">The instance to register.</param> public static void SetCachePolicyProvider(this HttpConfiguration config, ICachePolicyProvider provider) { if (config == null) { throw new ArgumentNullException("config"); } config.Properties[CachePolicyProviderKey] = provider; }
/// <summary> /// 创建 CachePolicy 实例 /// </summary> /// <param name="context">HTTP 上下文</param> /// <param name="token">缓存标识</param> /// <param name="provider">缓存策略提供程序</param> public CachePolicy( HttpContextBase context, CacheToken token, ICachePolicyProvider provider ) { HttpContext = context; CacheToken = token; Provider = provider; }
public SyncLookupHandler(T implementation, ICachePolicyProvider <T> cachePolicyProvider, ICacheProvider <T> cache) { _implementation = implementation; _cachePolicyProvider = cachePolicyProvider; _cache = cache; }