internal static TItem[] Set <TItem>(this NCacheWrapper cache, object[] keys, TItem[] values, CachingOptions options, Alachisoft.NCache.Runtime.Dependencies.CacheDependency dbDependency, StoreAs storingAs) { Logger.Log( "Setting items in bulk against respective keys with DbDependency '" + dbDependency + "'.", Microsoft.Extensions.Logging.LogLevel.Trace ); Alachisoft.NCache.Web.Caching.CacheItem[] cacheItems = new Alachisoft.NCache.Web.Caching.CacheItem[values.Count()]; for (int i = 0; i < values.Count(); i++) { cacheItems[i] = new Alachisoft.NCache.Web.Caching.CacheItem(values[i]); CachingOptionsUtil.CopyMetadata(ref cacheItems[i], options, dbDependency); } if (keys.Length > 0) { cache.InsertBulk(keys, cacheItems); } return(values); }
internal static TItem Set <TItem>(this NCacheWrapper cache, object key, TItem value, CachingOptions options, Alachisoft.NCache.Runtime.Dependencies.CacheDependency dbDependency, StoreAs storingAs) { Logger.Log( "Setting item '" + value + "' against key '" + key + "' with DbDependency '" + dbDependency + "'.", Microsoft.Extensions.Logging.LogLevel.Trace ); Alachisoft.NCache.Web.Caching.CacheItem cacheItem = new Alachisoft.NCache.Web.Caching.CacheItem(value); CachingOptionsUtil.CopyMetadata(ref cacheItem, options, dbDependency); cache.Insert(key, cacheItem); return(value); }
/// <summary> /// Initializes a new instance of the <see cref="CacheDependency"/> class that monitors an array of file paths (to files or /// directories), an array of cache keys, or both for changes. It also /// makes itself dependent upon another instance of the <see cref="CacheDependency"/> /// class and a time when the change monitoring begins. /// </summary> /// <param name="fileNames">An array of file paths (to files or directories) that the cached object /// is dependent upon. When any of these resources change, the cached object becomes obsolete and /// is removed from the cache.</param> /// <param name="cacheKeys">An array of cache keys that the new object monitors for changes. When /// any of these cache keys change, the cached object associated with this dependency object /// becomes obsolete and is removed from the cache.</param> /// <param name="dependency">Another instance of the <see cref="CacheDependency"/> class that this /// instance is dependent upon.</param> /// <param name="start">The time when change tracking begins.</param> /// <exception cref="ArgumentNullException"><paramref name="fileNames"/> or <paramref name="cacheKeys"/> contains a /// null reference (Nothing in Visual Basic).</exception> /// <remarks> /// If any of the files or directories in the array were to change or be removed from the array, /// the cached item becomes obsolete and is removed from the application's <see cref="Cache"/> object. /// <para> /// Also, if any of the directories or files specified in the <paramref name="fileNames"/> parameter is not found in the /// file system, they are treated as missing files. If any of them are created after the object with the /// dependency is added to the <see cref="Cache"/>, the cached object will be removed from the <see cref="Cache"/>.For example, /// assume that you add an object to the <see cref="Cache"/> with a dependency on the following file path: /// c:\stocks\xyz.dat. If that file is not found when the <see cref="CacheDependency"/> object is created, but is /// created later, the cached object is removed upon the creation of the xyz.dat file. /// </para> /// </remarks> public CacheDependency(string[] fileNames, string[] cacheKeys, CacheDependency dependency, DateTime start)//:base(start) { CacheDependency fileDependency = null; CacheDependency keyDependency = null; if (fileNames != null) { if (fileNames.Length == 0) { throw new ArgumentException("fileNames array must have atleast one file name"); } foreach (string fileName in fileNames) { if (fileName == null) { throw new ArgumentNullException("fileName"); } if (fileName == string.Empty) { throw new ArgumentException("fileName cannot be empty string"); } } fileDependency = new FileDependency(fileNames, start); } if (cacheKeys != null) { if (cacheKeys.Length == 0) { throw new ArgumentException("fileNames array must have atleast one file name"); } foreach (string cachekey in cacheKeys) { if (cachekey == null) { throw new ArgumentNullException("cacheKey"); } if (cachekey == string.Empty) { throw new ArgumentException("cacheKey cannot be empty string"); } } keyDependency = new KeyDependency(cacheKeys, start); } if (fileDependency != null || keyDependency != null || dependency != null) { if (_dependencies == null) { _dependencies = new List <CacheDependency>(); } if (fileDependency != null) { _dependencies.Add(fileDependency); } if (keyDependency != null) { _dependencies.Add(keyDependency); } if (dependency != null) { _dependencies.Add(dependency); } } _startAfter = start; }
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> /// Initializes a new instance of the <see cref="CacheDependency"/> class that monitors an array of /// file paths (to files or directories), an array of cache keys, or both for changes. /// It also makes itself dependent upon a separate instance of the <see cref="CacheDependency"/> class. /// </summary> /// <param name="fileNames">An array of file paths (to files or directories) that the cached object /// is dependent upon. When any of these resources change, the cached object becomes obsolete and /// is removed from the cache.</param> /// <param name="cacheKeys">An array of cache keys that the new object monitors for changes. When /// any of these cache keys change, the cached object associated with this dependency object /// becomes obsolete and is removed from the cache.</param> /// <param name="dependency">Another instance of the <see cref="CacheDependency"/> class that this /// instance is dependent upon.</param> /// <exception cref="ArgumentNullException"><paramref name="fileNames"/> or <paramref name="cacheKeys"/> contains a /// null reference (Nothing in Visual Basic).</exception> /// <remarks> /// If any of the files or directories in the array were to change or be removed from the array, /// the cached item becomes obsolete and is removed from the application's <see cref="Cache"/> object. /// <para> /// Also, if any of the directories or files specified in the <paramref name="fileNames"/> parameter is not found in the /// file system, they are treated as missing files. If any of them are created after the object with the /// dependency is added to the <see cref="Cache"/>, the cached object will be removed from the <see cref="Cache"/>.For example, /// assume that you add an object to the <see cref="Cache"/> with a dependency on the following file path: /// c:\stocks\xyz.dat. If that file is not found when the <see cref="CacheDependency"/> object is created, but is /// created later, the cached object is removed upon the creation of the xyz.dat file. /// </para> /// </remarks> public CacheDependency(string[] fileNames, string[] cacheKeys, CacheDependency dependency) : this(fileNames, cacheKeys, dependency, DateTime.Now) { }