/// <summary> /// Puts the result to cache. /// </summary> private void PutResultToCache(DbCacheKey key, object result, DbQueryInfo queryInfo) { var expiration = _commandInfo.Policy != null ? _commandInfo.Policy.GetExpirationTimeout(queryInfo) : TimeSpan.MaxValue; _commandInfo.Cache.PutItem(key, result, expiration); }
/// <summary> /// Puts the item to cache. /// </summary> public void PutItem(DbCacheKey key, object value, TimeSpan absoluteExpiration) { using (var stream = new MemoryStream()) { new BinaryFormatter().Serialize(stream, value); var valueBytes = stream.ToArray(); var cache = GetCacheWithExpiry(absoluteExpiration); ((ICacheInternal)cache).DoOutInOpExtension <object>(ExtensionId, OpPutItem, w => { WriteKey(key, w, true); w.WriteByteArray(valueBytes); }, null); } }
/// <summary> /// Gets the item from cache. /// </summary> public bool GetItem(DbCacheKey key, out object value) { var valueBytes = ((ICacheInternal)_cache).DoOutInOpExtension(ExtensionId, OpGetItem, w => WriteKey(key, w, false), r => r.ReadObject <byte[]>()); if (valueBytes == null) { value = null; return(false); } using (var ms = new MemoryStream(valueBytes)) { value = new BinaryFormatter().Deserialize(ms); } return(true); }
/// <summary> /// Writes the key. /// </summary> private static void WriteKey(DbCacheKey key, IBinaryRawWriter writer, bool includeNames) { writer.WriteString(key.Key); if (key.EntitySetVersions != null) { writer.WriteInt(key.EntitySetVersions.Count); // Versions should be in the same order, so we can't iterate over the dictionary. foreach (var entitySet in key.EntitySets) { writer.WriteLong(key.EntitySetVersions[entitySet.Name]); if (includeNames) { writer.WriteString(entitySet.Name); } } } else { writer.WriteInt(-1); } }
/// <summary> /// Writes the key. /// </summary> private static void WriteKey(DbCacheKey key, IBinaryRawWriter writer, bool includeNames) { writer.WriteString(key.Key); if (key.EntitySetVersions != null) { writer.WriteInt(key.EntitySetVersions.Count); // Versions should be in the same order, so we can't iterate over the dictionary. foreach (var entitySet in key.EntitySets) { writer.WriteLong(key.EntitySetVersions[entitySet.Name]); if (includeNames) writer.WriteString(entitySet.Name); } } else { writer.WriteInt(-1); } }
/// <summary> /// Puts the item to cache. /// </summary> public void PutItem(DbCacheKey key, object value, TimeSpan absoluteExpiration) { using (var stream = new MemoryStream()) { new BinaryFormatter().Serialize(stream, value); var valueBytes = stream.ToArray(); var cache = GetCacheWithExpiry(absoluteExpiration); ((ICacheInternal)cache).DoOutInOpExtension<object>(ExtensionId, OpPutItem, w => { WriteKey(key, w, true); w.WriteByteArray(valueBytes); }, null); } }
/// <summary> /// Gets the item from cache. /// </summary> public bool GetItem(DbCacheKey key, out object value) { var valueBytes = ((ICacheInternal) _cache).DoOutInOpExtension(ExtensionId, OpGetItem, w => WriteKey(key, w, false), r => r.ReadObject<byte[]>()); if (valueBytes == null) { value = null; return false; } using (var ms = new MemoryStream(valueBytes)) { value = new BinaryFormatter().Deserialize(ms); } return true; }
/// <summary> /// Puts the result to cache. /// </summary> private void PutResultToCache(DbCacheKey key, object result, DbQueryInfo queryInfo) { var expiration = _commandInfo.Policy != null ? _commandInfo.Policy.GetExpirationTimeout(queryInfo) : TimeSpan.MaxValue; _commandInfo.Cache.PutItem(key, result, expiration); }