/// <summary> /// On cache miss. /// </summary> protected internal override void OnCacheMiss(Container container, IQueryable query, string key) { // Patch model to include schema information in LinqToSql, this is a requirement for SqlDependency to work. LinqToSql.AddSchemaToModel(query); var dependency = new System.Data.SqlClient.SqlDependency(); dependency.OnChange += (sender, args) => { if (args.Info == SqlNotificationInfo.Invalid) { var unsupportedQueryHandler = UnsupportedQuery; if (unsupportedQueryHandler != null) { unsupportedQueryHandler(this, new SqlDependencyEventArgs(query)); } } else { container.Delete(key); } OnChangeReceived.Set(); }; CallContext.SetData(CookieName, dependency.Id); }
public LinqCacheConfiguration(Container container, Invalidator invalidator) { Invalidator = invalidator; Container = container; }
/// <summary> /// Whenever the cache is hit. /// </summary> protected internal override void OnCacheHit(Container container, IQueryable query, string key, object cachedValue) { container.Set(key, cachedValue, Duration); }
/// <summary> /// On initialization of the invalidator. /// </summary> protected internal virtual void OnInit(Container container, IQueryable query, string key) { }
/// <summary> /// After a value has been refreshed. /// </summary> protected internal virtual void OnCacheRefresh(Container container, IQueryable query, string key, object value) { }
/// <summary> /// After a cache miss has occured. /// </summary> protected internal virtual void OnCacheMiss(Container container, IQueryable query, string key) { }
/// <summary> /// After a cache hit has occured. /// </summary> protected internal virtual void OnCacheHit(Container container, IQueryable query, string key, object cachedValue) { }
/// <summary> /// On cache refresh. /// </summary> protected internal override void OnCacheRefresh(Container container, IQueryable query, string key, object value) { CallContext.FreeNamedDataSlot(CookieName); }
/// <summary> /// On init. /// </summary> protected internal override void OnInit(Container container, IQueryable query, string key) { _connectionString = LinqToSql.GetConnectionString(query) ?? EntityFramework.GetConnectionString(query); if (_connectionString == null) { throw LinqCacheException.ContextIsNotSupported; } try { System.Data.SqlClient.SqlDependency.Start(_connectionString); } catch (InvalidOperationException exception) { if (exception.Message == BrokerNotEnabledMessage) { throw LinqCacheException.BrokerIsNotEnabled(exception); } throw; } }