/// <summary> /// Remove all items from the cache. /// </summary> public void Clear() { if (!RedisCacheMessageSuppressionContext.IsSet(Name)) { if (IsolateTenants) { var message = new RedisPubSubPerTenantCacheMessage <TKey>(new PerTenantCacheMessage <RedisPubSubCacheMessage <TKey> >(new RedisPubSubCacheMessage <TKey>(RedisPubSubCacheMessageAction.Clear))); PerTenantChannel.Publish(message, PublishOptions.FireAndForget, true, RedisPubSubCacheHelpers.PerTenantMergeAction ); } else { Channel.Publish( new RedisPubSubCacheMessage <TKey>(RedisPubSubCacheMessageAction.Clear), PublishOptions.FireAndForget, true, RedisPubSubCacheHelpers.MergeAction ); } } using (new RedisCacheMessageSuppressionContext(Name)) { InnerCache.Clear(); } }
public void Set(string cacheKey, object value) { lock (CacheLock) { InnerCache.Add(cacheKey, value); } }
/// <summary> /// Gets the element at the specified index. /// </summary> /// <param name="index"></param> /// <returns></returns> public T this[int index] { get { return(InnerCache.RetrieveElement(index)); } }
/// <summary> /// Attempts to get a value from cache. /// If it is found in cache, return true, and the value. /// If it is not found in cache, return false, and use the valueFactory callback to generate and return the value. /// </summary> /// <param name="key">The key.</param> /// <param name="value"></param> /// <param name="valueFactory">A callback that can create the value.</param> /// <returns> /// True if the value came from cache, otherwise false. /// </returns> public bool TryGetOrAdd(TKey key, out TValue value, Func <TKey, TValue> valueFactory) { RedisValue redisValue; RedisKey redisKey = GetRedisKey(key); if (!_memoryStore.TryGetString(redisKey, out redisValue)) { if (InnerCache != null) { bool cameFromCache = InnerCache.TryGetOrAdd(key, out value, valueFactory); _memoryStore.StringSet(redisKey, GetRedisValue(key, value), KeyExpiry); return(cameFromCache); } value = valueFactory(key); _memoryStore.StringSet(redisKey, GetRedisValue(key, value), KeyExpiry); return(false); } value = GetValue(redisValue); return(true); }
/// <summary> /// Gets or sets the <see cref="System.Object" /> with the specified key. /// </summary> /// <value> /// The <see cref="System.Object" />. /// </value> /// <param name="key">The key.</param> /// <returns> /// The cached value if found; null otherwise. /// </returns> public TValue this[TKey key] { get { bool result; TValue value; result = InnerCache.TryGetValue(key, out value); if (result) { Interlocked.Increment(ref _hits); } else { Interlocked.Increment(ref _misses); } MetricReporter.NotifyHitsAndMissesChange(Name); return(value); } set { Add(key, value); } }
/// <summary> /// Gets the user account cache entry. /// </summary> /// <param name="username">The username.</param> /// <returns></returns> private UserAccountCacheEntry GetUserAccountCacheEntry(string username) { UserAccountCacheEntry entry; lock ( _innerLockObject ) { if (PasswordPolicyId == 0) { // Cache the password policy instance id PasswordPolicyId = Entity.GetId("core:passwordPolicyInstance"); } if (!InnerCache.TryGetValue(username, out entry)) { // We don't have a cache entry for this user name. // Get the user account by user name and add it to the cache UserAccount userAccountByName = Entity.GetByField <UserAccount>(username, true, new EntityRef("core", "name")).FirstOrDefault( ); if (userAccountByName == null) { return(null); } entry = AddAccount(userAccountByName); } } return(entry); }
public IEnumerable <string> Get(string key) { var keys = InnerCache.GetCacheKeys().Where(s => s.ToLower().Contains(key.ToLower())); keys = keys.OrderBy(q => q).ToList(); return(keys); }
/// <summary> /// Sorts the list based on a <see cref="T:System.ComponentModel.PropertyDescriptor"/> and a <see cref="T:System.ComponentModel.ListSortDirection"/>. /// </summary> /// <param name="property">The <see cref="T:System.ComponentModel.PropertyDescriptor"/> to sort by. /// </param><param name="direction">One of the <see cref="T:System.ComponentModel.ListSortDirection"/> values. /// </param><exception cref="T:System.NotSupportedException"><see cref="P:System.ComponentModel.IBindingList.SupportsSorting"/> is false. /// </exception> public void ApplySort(PropertyDescriptor property, ListSortDirection direction) { ListSortDescription[] descriptions = new[] { new ListSortDescription(property, direction) }; SortDescriptions = new ListSortDescriptionCollection(descriptions); PageProvider.Sort = property.Name + " " + (direction == ListSortDirection.Ascending ? "Asc" : "Desc"); InnerCache.Reset(); OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, 0)); }
private void UpdateIndex(string partionKey, string key) { var index = InnerCache.GetOrCreate(partionKey, entry => new HashSet <string>()); index.Add(key); InnerCache.Set(partionKey, index, CacheDuration); }
//GetSite public Site GetSite(string name) { if (!ContainsSite(name)) { return(null); } return((Site)InnerCache.GetValue(name)); }
private void RemoveSite(Site siteItem) { if (ContainsSite(siteItem)) { //Refresh Information InnerCache.Remove(siteItem.Name); } }
public async Task AddAsync(string cacheKey, DateTime absoluteExpiryDate, object dataToAdd) { if (dataToAdd == null || !IsCacheEnabled) { await Task.Delay(0); } await InnerCache.AddAsync(cacheKey, absoluteExpiryDate, dataToAdd); }
/// <summary> /// Returns an enumerator that iterates through the collection. /// </summary> /// <returns> /// A <see cref="T:System.Collections.Generic.IEnumerator`1" /> that can be used to iterate through the collection. /// </returns> public IEnumerator <KeyValuePair <TKey, TValue> > GetEnumerator( ) { if (InnerCache != null) { return(InnerCache.GetEnumerator( )); } throw new NotImplementedException( ); }
private void ResetExpirationTime <TValue>(ScopedCacheItem <TValue> cacheItem) { if (expireWithin.HasValue && useSlidingExpiration) { InnerCache.SetIfNotExists(cacheItem); cacheItem.ExpireIn = this.expireWithin.Value; InnerCache.SetExpirationTime(cacheItem); } }
protected async Task <IEnumerable <T> > GetListAsync(string partitionKey, string listKey, Func <ICacheEntry, Task <IEnumerable <T> > > factory) { var recordKey = $"{KeyPrefix}:ListOf{partitionKey}:{listKey}"; var result = await InnerCache.GetOrCreateAsync(recordKey, factory); UpdateIndex(partitionKey, recordKey); return(result); }
/// <summary> /// Returns an enumerator that iterates through a collection. /// </summary> /// <returns> /// An <see cref="T:System.Collections.IEnumerator" /> object that can be used to iterate through the collection. /// </returns> IEnumerator IEnumerable.GetEnumerator( ) { if (InnerCache != null) { return(InnerCache.GetEnumerator( )); } throw new NotImplementedException( ); }
public async Task InvalidateCacheItemAsync(string cacheKey) { if (!IsCacheEnabled) { await Task.Delay(0); } await InnerCache.InvalidateCacheItemAsync(cacheKey); }
public void InvalidateCacheItem(string cacheKey) { if (!IsCacheEnabled) { return; } InnerCache.InvalidateCacheItem(cacheKey); }
public async Task AddAsync(string cacheKey, TimeSpan slidingExpiryWindow, object dataToAdd) { if (dataToAdd == null || !IsCacheEnabled) { await Task.Delay(0); } await InnerCache.AddAsync(cacheKey, slidingExpiryWindow, dataToAdd); }
public void Add(string cacheKey, TimeSpan slidingExpiryWindow, object dataToAdd) { if (dataToAdd == null || !IsCacheEnabled) { return; } InnerCache.Add(cacheKey, slidingExpiryWindow, dataToAdd); }
public void Add(string cacheKey, DateTime absoluteExpiryDate, object dataToAdd) { if (dataToAdd == null || !IsCacheEnabled) { return; } InnerCache.Add(cacheKey, absoluteExpiryDate, dataToAdd); }
protected async Task <T> GetAsync(string partitionKey, string itemKey, Func <ICacheEntry, Task <T> > factory) { var recordKey = $"{KeyPrefix}:{partitionKey}:{itemKey}"; var result = await InnerCache.GetOrCreateAsync(recordKey, factory); UpdateIndex(partitionKey, recordKey); return(result); }
public virtual void Add(string ip, WhoIsInformation value) { Assert.ArgumentNotNull(ip, "ip"); Assert.ArgumentNotNull(value, "value"); if (!Enabled) { return; } InnerCache.Add(ip, value, Settings.GeoIpCacheExpiryTime); }
private async Task ResetExpirationTimeAsync <TValue>(ScopedCacheItem <TValue> cacheItem) { if (expireWithin.HasValue && useSlidingExpiration) { await InnerCache.SetIfNotExistsAsync(cacheItem).ConfigureAwait(false); cacheItem.ExpireIn = expireWithin.Value; await InnerCache.SetExpirationTimeAsync(cacheItem).ConfigureAwait(false); } }
/// <summary> /// Caches the entry invalidate internal. /// </summary> /// <param name="username">The username.</param> public void CacheEntryInvalidateInternal(string username) { if (_innerCache != null) { lock ( _innerLockObject ) { InnerCache.Remove(username); } } }
private T GetData <T>(string cacheKey, Func <T> getData) where T : class { T data = IsCacheEnabled ? InnerCache.Get <T>(cacheKey) : null; if (data == null) { data = getData(); } return(data); }
private T GetData <E, M, T>(string cacheKey, Func <Func <E, M>, T> getData, Func <E, M> transformData) where T : class { T data = IsCacheEnabled ? InnerCache.Get <T>(cacheKey) : null; if (data == null) { data = getData(transformData); } return(data); }
//AddSite public void AddSite(Site siteItem) { if (ContainsSite(siteItem)) { RemoveSite(siteItem); } var cacheItem = new SiteCacheItem(siteItem); InnerCache.Add(siteItem.Name, cacheItem); }
public CacheMethodTaken SetScoped <TValue>(String key, TValue value, DateTimeOffset valueTimestamp) { var directives = CacheDirectives.CurrentScope; if (directives.Method.HasFlag(CacheMethod.Set)) { InnerCache.Set(key, new ScopedValue <TValue>(value, valueTimestamp), GetRuntimePolicy(), regionName: null); return(CacheMethodTaken.Set); } return(CacheMethodTaken.None); }
public List <T> GetRules <T>(string key) where T : IBaseRule { List <T> returnRules = null; var rules = InnerCache.GetValue(key) as IEnumerable <T>; if (rules != null) { returnRules = rules.ToList(); } return(returnRules); }