/// <summary> /// Gets the specified tag. /// </summary> /// <param name="tag">The tag.</param> /// <param name="name">The name.</param> /// <param name="registration">The registration.</param> /// <param name="header">The header.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"></exception> public object Get(object tag, string name, IServiceCacheRegistration registration, out CacheItemHeader header) { if (registration == null) { throw new ArgumentNullException("registration"); } var version = (tag as DataCacheItemVersion); string regionName; if (!registration.UseHeaders) { header = null; } else if (version == null) { header = (CacheItemHeader)(!Settings.TryGetRegion(ref name, out regionName) ? Cache.Get(name + "#") : Cache.Get(name + "#", regionName)); } else { header = (CacheItemHeader)(!Settings.TryGetRegion(ref name, out regionName) ? Cache.GetIfNewer(name + "#", ref version) : Cache.GetIfNewer(name + "#", ref version, regionName)); } if (version == null) { return(!Settings.TryGetRegion(ref name, out regionName) ? Cache.Get(name) : Cache.Get(name, regionName)); } return(!Settings.TryGetRegion(ref name, out regionName) ? Cache.GetIfNewer(name, ref version) : Cache.GetIfNewer(name, ref version, regionName)); }
/// <summary> /// Tries the get value. /// </summary> /// <param name="registration">The registration.</param> /// <param name="recurses">The recurses.</param> /// <param name="foundRegistration">The found registration.</param> /// <returns></returns> public static bool TryGetValue(IServiceCacheRegistration registration, ref int recurses, out IServiceCacheRegistration foundRegistration) { _rwLock.EnterReadLock(); try { var registrar = registration.Registrar; if (registrar != null) { // local check var foreignRegistration = (registration as ServiceCacheForeignRegistration); if (foreignRegistration == null) { foundRegistration = registration; return(true); } // foreign recurse if (recurses++ > 4) { throw new InvalidOperationException(Local.ExceedRecurseCount); } // touch - starts foreign static constructor var foreignType = foreignRegistration.ForeignType; foreignType.InvokeMember("Touch", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Static, null, null, null); return(TryGetValue(foreignType, foreignRegistration.ForeignName, ref recurses, out foundRegistration)); } foundRegistration = null; return(false); } finally { _rwLock.ExitReadLock(); } }
/// <summary> /// Registers the specified registration. /// </summary> /// <param name="registration">The registration.</param> public void Register(IServiceCacheRegistration registration) { if (registration == null) { throw new ArgumentNullException("registration"); } _setRwLock.EnterWriteLock(); try { if (_set.Contains(registration)) { throw new InvalidOperationException(string.Format(Local.RedefineDataCacheAB, AnchorType.ToString(), registration.Name)); } // add var registrationName = registration.Name; if (string.IsNullOrEmpty(registrationName)) { throw new ArgumentNullException("registration.Name"); } if (registrationName.IndexOf("::") > -1) { throw new ArgumentException(string.Format(Local.ScopeCharacterNotAllowedA, registrationName), "registration"); } if (_setAsName.ContainsKey(registrationName)) { throw new ArgumentException(string.Format(Local.RedefineNameA, registrationName), "registration"); } _setAsName.Add(registrationName, registration); _set.Add(registration); // link-in registration.AttachRegistrar(this, _namePrefix + registrationName); } finally { _setRwLock.ExitWriteLock(); } }
/// <summary> /// Gets the specified registration. /// </summary> /// <param name="tag">The tag.</param> /// <param name="registration">The registration.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="System.NotImplementedException"></exception> public IEnumerable <CacheItemHeader> Get(object tag, IServiceCacheRegistration registration) { if (registration == null) { throw new ArgumentNullException("registration"); } throw new NotImplementedException(); }
/// <summary> /// Removes from cache the item associated with the key provided. /// </summary> /// <param name="tag">The tag.</param> /// <param name="name">The name.</param> /// <param name="registration">The registration.</param> /// <returns> /// The item removed from the Cache. If the value in the key parameter is not found, returns null. /// </returns> public object Remove(object tag, string name, IServiceCacheRegistration registration) { if (registration != null && registration.UseHeaders) { Cache.Remove(name + "#"); } return(Cache.Remove(name)); }
/// <summary> /// Gets the specified tag. /// </summary> /// <param name="tag">The tag.</param> /// <param name="name">The name.</param> /// <param name="registration">The registration.</param> /// <param name="header">The header.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"></exception> public object Get(object tag, string name, IServiceCacheRegistration registration, out CacheItemHeader header) { if (registration == null) { throw new ArgumentNullException("registration"); } header = (registration.UseHeaders ? (CacheItemHeader)Cache.Get(name + "#") : null); return(Cache.Get(name)); }
/// <summary> /// Removes from cache the item associated with the key provided. /// </summary> /// <param name="tag">The tag.</param> /// <param name="name">The name.</param> /// <param name="registration">The registration.</param> /// <returns> /// The item removed from the Cache. If the value in the key parameter is not found, returns null. /// </returns> public object Remove(object tag, string name, IServiceCacheRegistration registration) { string regionName; Settings.TryGetRegion(ref name, out regionName); if (registration != null && registration.UseHeaders) { Cache.Remove(name + "#", regionName); } return(Cache.Remove(name, regionName)); }
/// <summary> /// Gets the specified tag. /// </summary> /// <param name="tag">The tag.</param> /// <param name="name">The name.</param> /// <param name="registration">The registration.</param> /// <param name="header">The header.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"></exception> public object Get(object tag, string name, IServiceCacheRegistration registration, out CacheItemHeader header) { if (registration == null) { throw new ArgumentNullException("registration"); } object value; header = (registration.UseHeaders && _cache.TryGetValue(name + "#", out value) ? (CacheItemHeader)value : null); return(_cache.TryGetValue(name, out value) ? value : null); }
/// <summary> /// Gets the specified tag. /// </summary> /// <param name="tag">The tag.</param> /// <param name="name">The name.</param> /// <param name="registration">The registration.</param> /// <param name="header">The header.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"></exception> public object Get(object tag, string name, IServiceCacheRegistration registration, out CacheItemHeader header) { if (registration == null) { throw new ArgumentNullException("registration"); } string regionName; Settings.TryGetRegion(ref name, out regionName); header = (registration.UseHeaders ? (CacheItemHeader)Cache.Get(name + "#", regionName) : null); return(Cache.Get(name, regionName)); }
/// <summary> /// Sends the specified cache. /// </summary> /// <param name="cache">The cache.</param> /// <param name="registration">The registration.</param> /// <param name="tag">The tag.</param> /// <param name="messages">The messages.</param> /// <exception cref="System.NotImplementedException"></exception> public void Send(IServiceCache cache, IServiceCacheRegistration registration, object tag, params object[] messages) { if (cache == null) { throw new ArgumentNullException("cache"); } if (registration == null) { throw new ArgumentNullException("registration"); } var registration2 = (registration as ServiceCacheRegistration); if (registration2 == null) { throw new ArgumentException("must be ServiceCacheRegistration", "registration"); } var consumerInfos = registration2.GetConsumersFor(messages); if (!consumerInfos.GetEnumerator().MoveNext()) { return; } // var itemPolicy = registration2.ItemPolicy; if (itemPolicy == null) { throw new ArgumentNullException("registration.ItemPolicy"); } var useDBNull = ((cache.Settings.Options & ServiceCacheOptions.UseDBNullWithRegistrations) == ServiceCacheOptions.UseDBNullWithRegistrations); var distributedServiceCache = cache.BehaveAs <IDistributedServiceCache>(); object value; foreach (var header in cache.Get(tag, registration)) { foreach (var consumerInfo in consumerInfos) { if ((value = consumerInfo.Invoke(cache, tag, header)) != null) { if (distributedServiceCache == null) { SetUsingLock(cache, registration2, tag, header, useDBNull, value); } else { SetUsingCas(distributedServiceCache, registration2, tag, header, useDBNull, value); } } } } }
/// <summary> /// Removes from cache the item associated with the key provided. /// </summary> /// <param name="tag">The tag.</param> /// <param name="name">The key.</param> /// <param name="registration">The registration.</param> /// <returns> /// The item removed from the Cache. If the value in the key parameter is not found, returns null. /// </returns> public object Remove(object tag, string name, IServiceCacheRegistration registration) { object value; if (_cache.TryGetValue(name, out value)) { if (registration != null && registration.UseHeaders) { _cache.Remove(name + "#"); } _cache.Remove(name); return(value); } return(null); }
/// <summary> /// Removes from cache the item associated with the key provided. /// </summary> /// <param name="tag">The tag.</param> /// <param name="name">The name.</param> /// <param name="registration">The registration.</param> /// <returns> /// The item removed from the Cache. If the value in the key parameter is not found, returns null. /// </returns> public object Remove(object tag, string name, IServiceCacheRegistration registration) { if (registration != null && registration.UseHeaders) { Remove(tag, name + "#", null); } string regionName; var value = ((Settings.Options & ServiceCacheOptions.ReturnsCachedValueOnRemove) == 0 ? null : (!Settings.TryGetRegion(ref name, out regionName) ? Cache.Get(name) : Cache.Get(name, regionName))); // var version = (tag as DataCacheItemVersion); var lockHandle = (tag as DataCacheLockHandle); if (version == null && lockHandle == null) { if (!Settings.TryGetRegion(ref name, out regionName)) { Cache.Remove(name); } else { Cache.Remove(name, regionName); } } else if (version != null) { if (!Settings.TryGetRegion(ref name, out regionName)) { Cache.Remove(name, version); } else { Cache.Remove(name, version, regionName); } } else { if (!Settings.TryGetRegion(ref name, out regionName)) { Cache.Remove(name, lockHandle); } else { Cache.Remove(name, lockHandle, regionName); } } return(value); }
/// <summary> /// Gets the specified cache. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="cache">The cache.</param> /// <param name="registration">The registration.</param> /// <param name="tag">The tag.</param> /// <param name="values">The values.</param> /// <returns></returns> public T Get <T>(IServiceCache cache, IServiceCacheRegistration registration, object tag, object[] values) { if (cache == null) { throw new ArgumentNullException("cache"); } if (registration == null) { throw new ArgumentNullException("registration"); } var registration2 = (registration as ServiceCacheRegistration); if (registration2 == null) { throw new ArgumentException("must be ServiceCacheRegistration", "registration"); } var itemPolicy = registration2.ItemPolicy; if (itemPolicy == null) { throw new ArgumentNullException("registration.ItemPolicy"); } // fetch from cache var name = registration.AbsoluteName; string @namespace; if (values != null && values.Length > 0) { cache = cache.BehaveAs(values, out @namespace); } else { @namespace = null; } var useDBNull = ((cache.Settings.Options & ServiceCacheOptions.UseDBNullWithRegistrations) == ServiceCacheOptions.UseDBNullWithRegistrations); var distributedServiceCache = cache.BehaveAs <IDistributedServiceCache>(); if (distributedServiceCache == null) { return(GetUsingLock <T>(cache, registration2, tag, values, name, @namespace, useDBNull)); } return(GetUsingCas <T>(distributedServiceCache, registration2, tag, values, name, @namespace, useDBNull)); }
/// <summary> /// Gets the specified registration. /// </summary> /// <param name="tag">The tag.</param> /// <param name="registration">The registration.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"></exception> public IEnumerable <CacheItemHeader> Get(object tag, IServiceCacheRegistration registration) { if (registration == null) { throw new ArgumentNullException("registration"); } var registrationName = registration.AbsoluteName + "#"; CacheItemHeader value; var e = Cache.GetEnumerator(); while (e.MoveNext()) { var key = (e.Key as string); if (key == null || !key.EndsWith(registrationName) || (value = (e.Value as CacheItemHeader)) == null) { continue; } yield return(value); } }
//public void Update(IServiceCache cache, IServiceCacheRegistration registration, object tag, object value) //{ // if (cache == null) // throw new ArgumentNullException("cache"); // if (registration == null) // throw new ArgumentNullException("registration"); // var registration2 = (registration as ServiceCacheRegistration); // if (registration2 == null) // throw new ArgumentException("must be ServiceCacheRegistration", "registration"); // var itemPolicy = registration2.ItemPolicy; // if (itemPolicy == null) // throw new ArgumentNullException("registration.ItemPolicy"); // var useDBNull = ((cache.Settings.Options & ServiceCacheOptions.UseDBNullWithRegistrations) == ServiceCacheOptions.UseDBNullWithRegistrations); // var distributedServiceCache = cache.BehaveAs<IDistributedServiceCache>(); // if (distributedServiceCache == null) // SetUsingLock(cache, registration2, tag, header, useDBNull, value); // else // SetUsingCas(distributedServiceCache, registration2, tag, header, useDBNull, value); //} /// <summary> /// Removes the specified cache. /// </summary> /// <param name="cache">The cache.</param> /// <param name="registration">The registration.</param> public void Remove(IServiceCache cache, IServiceCacheRegistration registration) { if (cache == null) { throw new ArgumentNullException("cache"); } if (registration == null) { throw new ArgumentNullException("registration"); } var registration2 = (registration as ServiceCacheRegistration); if (registration2 == null) { throw new ArgumentException("must be ServiceCacheRegistration", "registration"); } foreach (var name in registration2.Keys) { cache.Remove(null, name, registration); } }
/// <summary> /// Gets the specified registration. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="registration">The registration.</param> /// <returns></returns> public static T Get <T>(IServiceCacheRegistration registration) { return(ServiceCacheManager.Current.Get <T>(registration, null, null)); }
/// <summary> /// Gets the many. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="registration">The registration.</param> /// <returns></returns> public static IEnumerable <T> GetMany <T>(IServiceCacheRegistration registration) { return(ServiceCacheManager.Current.Get <IEnumerable <T> >(registration, null, null)); }
/// <summary> /// Gets the many. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="registration">The registration.</param> /// <param name="tag">The tag.</param> /// <param name="values">The values.</param> /// <returns></returns> public static IEnumerable <T> GetMany <T>(IServiceCacheRegistration registration, object tag, object[] values) { return(ServiceCacheManager.Current.Get <IEnumerable <T> >(registration, tag, values)); }
/// <summary> /// Removes from cache the item associated with the key provided. /// </summary> /// <param name="tag">The tag.</param> /// <param name="name">The name.</param> /// <param name="registration">The registration.</param> /// <returns> /// The item removed from the Cache. If the value in the key parameter is not found, returns null. /// </returns> public object Remove(object tag, string name, IServiceCacheRegistration registration) { if (registration != null && registration.UseHeaders) Remove(tag, name + "#", null); string regionName; var value = ((Settings.Options & ServiceCacheOptions.ReturnsCachedValueOnRemove) == 0 ? null : (!Settings.TryGetRegion(ref name, out regionName) ? Cache.Get(name) : Cache.Get(name, regionName))); // var version = (tag as DataCacheItemVersion); var lockHandle = (tag as DataCacheLockHandle); if (version == null && lockHandle == null) { if (!Settings.TryGetRegion(ref name, out regionName)) Cache.Remove(name); else Cache.Remove(name, regionName); } else if (version != null) { if (!Settings.TryGetRegion(ref name, out regionName)) Cache.Remove(name, version); else Cache.Remove(name, version, regionName); } else { if (!Settings.TryGetRegion(ref name, out regionName)) Cache.Remove(name, lockHandle); else Cache.Remove(name, lockHandle, regionName); } return value; }
/// <summary> /// Gets the specified tag. /// </summary> /// <param name="tag">The tag.</param> /// <param name="name">The name.</param> /// <param name="registration">The registration.</param> /// <param name="header">The header.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"></exception> public object Get(object tag, string name, IServiceCacheRegistration registration, out CacheItemHeader header) { if (registration == null) throw new ArgumentNullException("registration"); var version = (tag as DataCacheItemVersion); string regionName; if (!registration.UseHeaders) header = null; else if (version == null) header = (CacheItemHeader)(!Settings.TryGetRegion(ref name, out regionName) ? Cache.Get(name + "#") : Cache.Get(name + "#", regionName)); else header = (CacheItemHeader)(!Settings.TryGetRegion(ref name, out regionName) ? Cache.GetIfNewer(name + "#", ref version) : Cache.GetIfNewer(name + "#", ref version, regionName)); if (version == null) return (!Settings.TryGetRegion(ref name, out regionName) ? Cache.Get(name) : Cache.Get(name, regionName)); return (!Settings.TryGetRegion(ref name, out regionName) ? Cache.GetIfNewer(name, ref version) : Cache.GetIfNewer(name, ref version, regionName)); }
/// <summary> /// Gets the specified registration. /// </summary> /// <param name="tag">The tag.</param> /// <param name="registration">The registration.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"></exception> public IEnumerable<CacheItemHeader> Get(object tag, IServiceCacheRegistration registration) { if (registration == null) throw new ArgumentNullException("registration"); var registrationName = registration.AbsoluteName + "#"; CacheItemHeader value; var e = Cache.GetEnumerator(); while (e.MoveNext()) { var key = (e.Key as string); if (key == null || !key.EndsWith(registrationName) || (value = (e.Value as CacheItemHeader)) == null) continue; yield return value; } }
public IEnumerable <CacheItemHeader> Get(object tag, IServiceCacheRegistration registration) { return(_parent.Get(tag, registration)); }
/// <summary> /// Removes from cache the item associated with the key provided. /// </summary> /// <param name="tag">The tag.</param> /// <param name="name">The name.</param> /// <param name="registration">The registration.</param> /// <returns> /// The item removed from the Cache. If the value in the key parameter is not found, returns null. /// </returns> public object Remove(object tag, string name, IServiceCacheRegistration registration) { throw new NotSupportedException(); }
/// <summary> /// Gets the specified tag. /// </summary> /// <param name="tag">The tag.</param> /// <param name="name">The name.</param> /// <param name="registration">The registration.</param> /// <param name="header">The header.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"></exception> public object Get(object tag, string name, IServiceCacheRegistration registration, out CacheItemHeader header) { if (registration == null) throw new ArgumentNullException("registration"); throw new NotImplementedException(); }
public object Remove(object tag, string name, IServiceCacheRegistration registration) { return(_parent.Remove(tag, _namespace + name, registration)); }
/// <summary> /// Gets the specified tag. /// </summary> /// <param name="tag">The tag.</param> /// <param name="name">The name.</param> /// <param name="registration">The registration.</param> /// <param name="header">The header.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"></exception> public object Get(object tag, string name, IServiceCacheRegistration registration, out CacheItemHeader header) { if (registration == null) throw new ArgumentNullException("registration"); header = (registration.UseHeaders ? (CacheItemHeader)Cache.Get(name + "#") : null); return Cache.Get(name); }
/// <summary> /// Removes the specified registration. /// </summary> /// <param name="registration">The registration.</param> /// <returns></returns> public bool Remove(IServiceCacheRegistration registration) { _setRwLock.EnterWriteLock(); try { _setAsName.Remove(registration.Name); return(_set.Remove(registration)); } finally { _setRwLock.ExitWriteLock(); } }
/// <summary> /// Removes from cache the item associated with the key provided. /// </summary> /// <param name="tag">The tag.</param> /// <param name="name">The name.</param> /// <param name="registration">The registration.</param> /// <returns> /// The item removed from the Cache. If the value in the key parameter is not found, returns null. /// </returns> public object Remove(object tag, string name, IServiceCacheRegistration registration) { if (registration != null && registration.UseHeaders) Cache.Remove(name + "#"); return Cache.Remove(name); }
/// <summary> /// Gets the specified registration. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="registration">The registration.</param> /// <param name="tag">The tag.</param> /// <param name="values">The values.</param> /// <returns></returns> public static T Get <T>(IServiceCacheRegistration registration, object tag, object[] values) { return(ServiceCacheManager.Current.Get <T>(registration, tag, values)); }
/// <summary> /// Gets the specified registration. /// </summary> /// <param name="tag">The tag.</param> /// <param name="registration">The registration.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="System.NotImplementedException"></exception> public IEnumerable<CacheItemHeader> Get(object tag, IServiceCacheRegistration registration) { if (registration == null) throw new ArgumentNullException("registration"); throw new NotImplementedException(); }
/// <summary> /// Initializes a new instance of the <see cref="ServiceCacheByDispatcher" /> struct. /// </summary> /// <param name="registration">The registration.</param> /// <param name="values">The values.</param> /// <param name="header">The header.</param> public ServiceCacheByDispatcher(IServiceCacheRegistration registration, object[] values, CacheItemHeader header) { Registration = registration; Values = values; Header = header; }
/// <summary> /// Gets the query. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="registration">The registration.</param> /// <param name="tag">The tag.</param> /// <returns></returns> public static IQueryable <T> GetQuery <T>(IServiceCacheRegistration registration, object tag) { return(ServiceCacheManager.Current.Get <IQueryable <T> >(registration, tag, null)); }
/// <summary> /// Gets the specified cached item. /// </summary> /// <param name="registration">The registration.</param> /// <returns></returns> public static object Get(IServiceCacheRegistration registration) { return(ServiceCacheManager.Current.Get <object>(registration, null, null)); }
/// <summary> /// Determines whether the specified key contains key. /// </summary> /// <param name="registration">The registration.</param> /// <returns> /// <c>true</c> if the specified key contains key; otherwise, <c>false</c>. /// </returns> public bool Contains(IServiceCacheRegistration registration) { _setRwLock.EnterReadLock(); try { return(_set.Contains(registration)); } finally { _setRwLock.ExitReadLock(); } }
public object Get(object tag, string name, IServiceCacheRegistration registration, out CacheItemHeader header) { return(_parent.Get(tag, _namespace + name, registration, out header)); }