internal static List <TItem> Set <TItem>(this NCacheWrapper cache, object key, Dictionary <string, TItem> value, CachingOptions options, Alachisoft.NCache.Runtime.Dependencies.CacheDependency dbDependency, StoreAs storingAs) { Logger.Log( "About to set values with options " + options.ToLog() + ", DbDependency '" + dbDependency + "' and StoringAs '" + storingAs + "'.", Microsoft.Extensions.Logging.LogLevel.Trace ); // Add entities if stroing as seperateEntities if (storingAs == StoreAs.SeperateEntities) { Logger.Log("Values are about to be set as separate entities.", Microsoft.Extensions.Logging.LogLevel.Trace); cache.Set(value.Keys.ToArray(), value.Values.ToArray(), options, dbDependency, storingAs); } // from here onwards is the enumerator logic and now it is being done in "else" after we have moved to tags based result set regeneration else { Logger.Log("Values are about to be set as collection.", Microsoft.Extensions.Logging.LogLevel.Trace); // Add query enumerator CacheEntry entry = cache.CreateEntry(key); // Setting options if (options != null) { entry.SetOptions(options); } // Setting Value if (storingAs == StoreAs.Collection) { entry.Value = value.Values.ToList(); } // Mind that this is not the user specified option but the end storing methodology entry.StoredAs = storingAs; // Set dependencies in the entry var aggregateDependency = new AggregateCacheDependency(); if (dbDependency != null) { aggregateDependency.Add(dbDependency); } entry.Dependencies = aggregateDependency; cache.Set(key, entry, options, dbDependency, storingAs); } return(value.Values.ToList()); }
/// <summary> /// Inserts instance of an entity in the cache. Any exisiting entity will be overwritten in the cache. /// Entity should be a part of the database context or else the method will throw an exception. /// </summary> /// <param name="entity">Instance of the entity to be inserted.</param> /// <param name="cacheKey">cache key that was used to insert the entity.</param> /// <param name="options">Caching options to be used while storing the entity. Note that some of the options /// might be overridden such as StoreAs option will always be <see cref="StoreAs.SeperateEntities"/>.</param> public void Insert(object entity, out string cacheKey, CachingOptions options) { Logger.Log( "Inserting entity '" + entity + "' with options " + options.ToLog() + "", Microsoft.Extensions.Logging.LogLevel.Trace ); if (IsValidEntity(entity)) { NCacheWrapper nCacheWrapper = QueryCacheManager.Cache; // Generate key using the key generator from NCacheWrapper cacheKey = nCacheWrapper.DefaultKeyGen.GetKey(CurrentContext, entity); // // Items are stored as separate entities in this API because only separate APIs can make it // to this section of code. List or other similar data structures will fail on IsValidEntity // so only individual entities will make it to here. // nCacheWrapper.Set(cacheKey, entity, options, null, StoreAs.SeperateEntities); return; } else { throw new Exception("Entity type and context do not match"); } }
internal static TItem SetAsCacheEntry <TItem>(this NCacheWrapper cache, object key, TItem value, CachingOptions options, CacheDependency dbDependency) { Logger.Log( "Setting CacheEntry '" + value + "' against key '" + key + "' with DbDependency '" + dbDependency + "'", Microsoft.Extensions.Logging.LogLevel.Trace ); CacheEntry entry = cache.CreateEntry(key); if (options != null) { entry.SetOptions(options); } if (dbDependency != null) { entry.Dependencies = dbDependency; } entry.Value = value; cache.Set(key, entry, options, dbDependency, options.StoreAs); return(value); }