// //==================================================================================================== /// <summary> /// save object directly to cache. /// </summary> /// <param name="key"></param> /// <param name="cacheDocument">Either a string, a date, or a serializable object</param> /// <param name="invalidationDate"></param> /// <remarks></remarks> private void storeCacheDocument(string key, CacheDocumentClass cacheDocument) { try { // if (string.IsNullOrEmpty(key)) { throw new ArgumentException("cache key cannot be blank"); } string typeMessage = ""; string serverKey = createServerKey(key); if (core.serverConfig.enableLocalMemoryCache) { // // -- save local memory cache typeMessage = "local-memory"; storeCacheDocument_MemoryCache(serverKey, cacheDocument); } if (core.serverConfig.enableLocalFileCache) { // // -- save local file cache typeMessage = "local-file"; string serializedData = SerializeObject(cacheDocument); using (System.Threading.Mutex mutex = new System.Threading.Mutex(false, serverKey)) { mutex.WaitOne(); core.privateFiles.saveFile("appCache\\" + FileController.encodeDosFilename(serverKey + ".txt"), serializedData); mutex.ReleaseMutex(); } } if (core.serverConfig.enableRemoteCache) { typeMessage = "remote"; if (remoteCacheInitialized) { // // -- save remote cache if (!cacheClient.Store(Enyim.Caching.Memcached.StoreMode.Set, serverKey, cacheDocument, cacheDocument.invalidationDate)) { // // -- store failed LogController.logError(core, "Enyim cacheClient.Store failed, no details available."); } } } // LogController.logTrace(core, "cacheType [" + typeMessage + "], key [" + key + "], expires [" + cacheDocument.invalidationDate + "], depends on [" + string.Join(",", cacheDocument.dependentKeyList) + "], points to [" + string.Join(",", cacheDocument.keyPtr) + "]"); // } catch (Exception ex) { LogController.logError(core, ex); } }
/// <summary> /// Updates an item in the cache with a cache key to reference its location, but only if it has not been changed since the last retrieval. The invoker must pass in the value returned by <see cref="M:MultiGet"/> called "cas" value. If this value matches the server's value, the item will be updated; otherwise the update fails. /// </summary> /// <param name="key">The key used to reference the item.</param> /// <param name="value">The data to be stored.</param> /// <param name="offset">A 32 bit integer that represents the index of the first byte to store.</param> /// <param name="length">A 32 bit integer that represents the number of bytes to store.</param> /// <param name="cas">The unique value returned by <see cref="M:MultiGet"/>.</param> /// <param name="expiresAt">The time when the item is invalidated in the cache.</param> public bool CheckAndSet(string key, byte[] value, int offset, int length, ulong cas, DateTime expiresAt) { return(MemcachedClient.Store(this.pool, StoreCommand.CheckAndSet, key, value, cas, offset, length, TimeSpan.MinValue, expiresAt)); }
/// <summary> /// Updates an item in the cache with a cache key to reference its location, but only if it has not been changed since the last retrieval. The invoker must pass in the value returned by <see cref="M:MultiGet"/> called "cas" value. If this value matches the server's value, the item will be updated; otherwise the update fails. /// </summary> /// <param name="key">The key used to reference the item.</param> /// <param name="value">The object to be inserted into the cache.</param> /// <param name="cas">The unique value returned by <see cref="M:MultiGet"/>.</param> /// <param name="expiresAt">The time when the item is invalidated in the cache.</param> public bool CheckAndSet(string key, object value, ulong cas, DateTime expiresAt) { return(MemcachedClient.Store(this.pool, StoreCommand.CheckAndSet, key, value, cas, TimeSpan.MinValue, expiresAt)); }
/// <summary> /// Updates an item in the cache with a cache key to reference its location, but only if it has not been changed since the last retrieval. The invoker must pass in the value returned by <see cref="M:MultiGet"/> called "cas" value. If this value matches the server's value, the item will be updated; otherwise the update fails. /// </summary> /// <param name="key">The key used to reference the item.</param> /// <param name="value">The object to be inserted into the cache.</param> /// <param name="cas">The unique value returned by <see cref="M:MultiGet"/>.</param> /// <param name="validFor">The interval after the item is invalidated in the cache.</param> public bool CheckAndSet(string key, object value, ulong cas, TimeSpan validFor) { return(MemcachedClient.Store(this.pool, StoreCommand.CheckAndSet, key, value, cas, validFor, DateTime.MinValue)); }
/// <summary> /// Updates an item in the cache with a cache key to reference its location, but only if it has not been changed since the last retrieval. The invoker must pass in the value returned by <see cref="M:MultiGet"/> called "cas" value. If this value matches the server's value, the item will be updated; otherwise the update fails. /// </summary> /// <param name="key">The key used to reference the item.</param> /// <param name="value">The data to be stored.</param> /// <param name="offset">A 32 bit integer that represents the index of the first byte to store.</param> /// <param name="length">A 32 bit integer that represents the number of bytes to store.</param> /// <param name="cas">The unique value returned by <see cref="M:MultiGet"/>.</param> /// <remarks>The item does not expire unless it is removed due memory pressure.</remarks> public bool CheckAndSet(string key, byte[] value, int offset, int length, ulong cas) { return(MemcachedClient.Store(this.pool, StoreCommand.CheckAndSet, key, value, cas, offset, length, MemcachedClient.Infinite, DateTime.MinValue)); }
/// <summary> /// Updates an item in the cache with a cache key to reference its location, but only if it has not been changed since the last retrieval. The invoker must pass in the value returned by <see cref="M:MultiGet"/> called "cas" value. If this value matches the server's value, the item will be updated; otherwise the update fails. /// </summary> /// <param name="key">The key used to reference the item.</param> /// <param name="value">The object to be inserted into the cache.</param> /// <param name="cas">The unique value returned by <see cref="M:MultiGet"/>.</param> /// <remarks>The item does not expire unless it is removed due memory pressure.</remarks> public bool CheckAndSet(string key, object value, ulong cas) { return(MemcachedClient.Store(this.pool, StoreCommand.CheckAndSet, key, value, cas, MemcachedClient.Infinite, DateTime.MinValue)); }
/// <summary> /// Inserts the data before the specified item's data. /// </summary> /// <returns>true if the data was successfully stored; false otherwise.</returns> public bool Prepend(string key, byte[] data) { return(MemcachedClient.Store(this.pool, StoreCommand.Prepend, key, data, 0, MemcachedClient.Infinite, DateTime.MinValue)); }
/// <summary> /// Inserts a range of bytes (usually memory area or serialized data) into the cache with a cache key to reference its location. /// </summary> /// <param name="mode">Defines how the item is stored in the cache.</param> /// <param name="key">The key used to reference the item.</param> /// <param name="value">The data to be stored.</param> /// <param name="offset">A 32 bit integer that represents the index of the first byte to store.</param> /// <param name="length">A 32 bit integer that represents the number of bytes to store.</param> /// <param name="expiresAt">The time when the item is invalidated in the cache.</param> /// <returns>true if the item was successfully stored in the cache; false otherwise.</returns> public bool Store(StoreMode mode, string key, byte[] value, int offset, int length, DateTime expiresAt) { return(MemcachedClient.Store(this.pool, (StoreCommand)mode, key, value, 0, offset, length, TimeSpan.MinValue, expiresAt)); }
/// <summary> /// Inserts an item into the cache with a cache key to reference its location. /// </summary> /// <param name="mode">Defines how the item is stored in the cache.</param> /// <param name="key">The key used to reference the item.</param> /// <param name="value">The object to be inserted into the cache.</param> /// <param name="expiresAt">The time when the item is invalidated in the cache.</param> /// <returns>true if the item was successfully stored in the cache; false otherwise.</returns> public bool Store(StoreMode mode, string key, object value, DateTime expiresAt) { return(MemcachedClient.Store(this.pool, (StoreCommand)mode, key, value, 0, TimeSpan.MinValue, expiresAt)); }
/// <summary> /// Inserts an item into the cache with a cache key to reference its location. /// </summary> /// <param name="mode">Defines how the item is stored in the cache.</param> /// <param name="key">The key used to reference the item.</param> /// <param name="value">The object to be inserted into the cache.</param> /// <param name="validFor">The interval after the item is invalidated in the cache.</param> /// <returns>true if the item was successfully stored in the cache; false otherwise.</returns> public bool Store(StoreMode mode, string key, object value, TimeSpan validFor) { return(MemcachedClient.Store(this.pool, (StoreCommand)mode, key, value, 0, validFor, DateTime.MinValue)); }
/// <summary> /// Inserts a range of bytes (usually memory area or serialized data) into the cache with a cache key to reference its location. /// </summary> /// <param name="mode">Defines how the item is stored in the cache.</param> /// <param name="key">The key used to reference the item.</param> /// <param name="value">The data to be stored.</param> /// <param name="offset">A 32 bit integer that represents the index of the first byte to store.</param> /// <param name="length">A 32 bit integer that represents the number of bytes to store.</param> /// <remarks>The item does not expire unless it is removed due memory pressure.</remarks> /// <returns>true if the item was successfully stored in the cache; false otherwise.</returns> public bool Store(StoreMode mode, string key, byte[] value, int offset, int length) { return(MemcachedClient.Store(this.pool, (StoreCommand)mode, key, value, 0, offset, length, MemcachedClient.Infinite, DateTime.MinValue)); }
/// <summary> /// Inserts an item into the cache with a cache key to reference its location. /// </summary> /// <param name="mode">Defines how the item is stored in the cache.</param> /// <param name="key">The key used to reference the item.</param> /// <param name="value">The object to be inserted into the cache.</param> /// <remarks>The item does not expire unless it is removed due memory pressure.</remarks> /// <returns>true if the item was successfully stored in the cache; false otherwise.</returns> public bool Store(StoreMode mode, string key, object value) { return(MemcachedClient.Store(this.pool, (StoreCommand)mode, key, value, 0, MemcachedClient.Infinite, DateTime.MinValue)); }
public bool Put(string key, object value) { return(mc.Store(StoreMode.Set, key, value)); }
public bool Add <T>(string key, T value) { return(Execute(() => client.Store(InnerClient.Memcached.StoreMode.Add, key, value))); }