本文整理汇总了C#中System.IO.MemoryStream.WriteControlBytePlaceHolder方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryStream.WriteControlBytePlaceHolder方法的具体用法?C# MemoryStream.WriteControlBytePlaceHolder怎么用?C# MemoryStream.WriteControlBytePlaceHolder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.MemoryStream
的用法示例。
在下文中一共展示了MemoryStream.WriteControlBytePlaceHolder方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveTagged
/// <summary>
/// Removes all serialized objects associated with the given tag names and optionally with keys matching the given pattern.
/// WARNING: THIS IS A VERY EXPENSIVE OPERATION FOR LARGE TAG CACHES. USE WITH CAUTION.
/// </summary>
/// <param name="tagNames">The tag names.</param>
/// <param name="pattern">The search pattern (RegEx). Optional. If not specified, the default of "*" is used to indicate match all.</param>
public void RemoveTagged(IEnumerable<string> tagNames, string pattern = "*")
{
// Sanitize
if (tagNames == null)
{
throw new ArgumentNullException("tagNames");
}
if (!tagNames.Any())
{
throw new ArgumentException("must have at least one element", "tagNames");
}
if (string.IsNullOrWhiteSpace(pattern))
{
throw new ArgumentException("cannot be null, empty, or white space", "pattern");
}
byte[] command;
using (var memoryStream = new MemoryStream())
{
memoryStream.WriteControlBytePlaceHolder();
memoryStream.Write("del-tag");
memoryStream.WriteSpace();
memoryStream.Write(pattern);
foreach (var tagName in tagNames)
{
memoryStream.WriteSpace();
memoryStream.Write(tagName);
}
command = memoryStream.ToArray();
}
// Set control byte
command.SetControlByte(DacheProtocolHelper.MessageType.RepeatingCacheKeys);
// Send
_client.Send(command);
}
示例2: GetTagged
/// <summary>
/// Gets all serialized objects associated with the given tag name.
/// </summary>
/// <param name="tagNames">The tag names.</param>
/// <returns>A list of the serialized objects.</returns>
public List<byte[]> GetTagged(IEnumerable<string> tagNames)
{
// Sanitize
if (tagNames == null)
{
throw new ArgumentNullException("tagNames");
}
if (!tagNames.Any())
{
throw new ArgumentException("must have at least one element", "tagNames");
}
byte[] command = null;
using (var memoryStream = new MemoryStream())
{
memoryStream.WriteControlBytePlaceHolder();
memoryStream.Write("get-tag");
foreach (var tagName in tagNames)
{
memoryStream.WriteSpace();
memoryStream.Write(tagName);
}
command = memoryStream.ToArray();
}
// Set control byte
command.SetControlByte(DacheProtocolHelper.MessageType.RepeatingCacheKeys);
// Send and receive
command = _client.SendReceive(command);
// Parse string
var commandResult = DacheProtocolHelper.CommunicationEncoding.GetString(command);
// Verify that we got something
if (commandResult == null)
{
return null;
}
// Parse command from bytes
var commandResultParts = commandResult.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
return ParseCacheObjects(commandResultParts);
}
示例3: Remove
/// <summary>
/// Removes the serialized objects at the given cache keys from the cache.
/// </summary>
/// <param name="cacheKeys">The cache keys.</param>
public void Remove(IEnumerable<string> cacheKeys)
{
// Sanitize
if (cacheKeys == null)
{
throw new ArgumentNullException("cacheKeys");
}
if (!cacheKeys.Any())
{
throw new ArgumentException("must have at least one element", "cacheKeys");
}
byte[] command = null;
using (var memoryStream = new MemoryStream())
{
memoryStream.WriteControlBytePlaceHolder();
memoryStream.Write("del");
foreach (var cacheKey in cacheKeys)
{
memoryStream.WriteSpace();
memoryStream.Write(cacheKey);
}
command = memoryStream.ToArray();
}
// Set control byte
command.SetControlByte(DacheProtocolHelper.MessageType.RepeatingCacheKeys);
// Send
_client.Send(command);
}
示例4: GetCacheKeysTagged
/// <summary>
/// Gets all cache keys associated with the given tag names and optionally matching the given pattern.
/// WARNING: THIS IS A VERY EXPENSIVE OPERATION FOR LARGE TAG CACHES. USE WITH CAUTION.
/// </summary>
/// <param name="tagNames">The tag names.</param>
/// <param name="pattern">The search pattern (RegEx). Optional. If not specified, the default of "*" is used to indicate match all.</param>
/// <returns>The list of cache keys matching the provided pattern.</returns>
public List<byte[]> GetCacheKeysTagged(IEnumerable<string> tagNames, string pattern = "*")
{
if (tagNames == null)
{
throw new ArgumentNullException("tagNames");
}
if (!tagNames.Any())
{
throw new ArgumentException("must have at least one element", "tagNames");
}
if (string.IsNullOrWhiteSpace(pattern))
{
throw new ArgumentException("cannot be null, empty, or white space", "pattern");
}
byte[] command;
using (var memoryStream = new MemoryStream())
{
memoryStream.WriteControlBytePlaceHolder();
memoryStream.Write("keys-tag");
memoryStream.WriteSpace();
memoryStream.Write(pattern);
foreach (var tagName in tagNames)
{
memoryStream.WriteSpace();
memoryStream.Write(tagName);
}
command = memoryStream.ToArray();
}
// Set control byte
command.SetControlByte(DacheProtocolHelper.MessageType.Literal);
// Send and receive
var rawResult = _client.SendReceive(command);
// Verify that we got something
if (rawResult == null)
{
return null;
}
// Parse string
var decodedResult = DacheProtocolHelper.CommunicationEncoding.GetString(rawResult);
if (string.IsNullOrWhiteSpace(decodedResult))
{
return null;
}
// Parse command from bytes
var commandResultParts = decodedResult.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
return ParseCacheObjects(commandResultParts);
}
示例5: GetCacheKeys
/// <summary>
/// Gets all cache keys, optionally matching the provided pattern.
/// WARNING: THIS IS A VERY EXPENSIVE OPERATION FOR LARGE CACHES. USE WITH CAUTION.
/// </summary>
/// <param name="pattern">The search pattern (RegEx). Optional. If not specified, the default of "*" is used to indicate match all.</param>
/// <returns>The list of cache keys matching the provided pattern</returns>
public List<byte[]> GetCacheKeys(string pattern = "*")
{
// Sanitize
if (string.IsNullOrWhiteSpace(pattern))
{
throw new ArgumentException("cannot be null, empty, or white space", "pattern");
}
byte[] command;
using (var memoryStream = new MemoryStream())
{
memoryStream.WriteControlBytePlaceHolder();
memoryStream.Write("keys {0}", pattern);
command = memoryStream.ToArray();
}
// Set control byte
command.SetControlByte(DacheProtocolHelper.MessageType.Literal);
// Send and receive
var rawResult = _client.SendReceive(command);
// Verify that we got something
if (rawResult == null)
{
return null;
}
// Parse string
var decodedResult = DacheProtocolHelper.CommunicationEncoding.GetString(rawResult);
if (string.IsNullOrWhiteSpace(decodedResult))
{
return null;
}
// Parse command from bytes
var commandResultParts = decodedResult.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
return ParseCacheObjects(commandResultParts);
}
示例6: Clear
/// <summary>
/// Clears the cache.
/// </summary>
public void Clear()
{
byte[] command;
using (var memoryStream = new MemoryStream())
{
memoryStream.WriteControlBytePlaceHolder();
memoryStream.Write("clear");
command = memoryStream.ToArray();
}
// Set control byte
command.SetControlByte(DacheProtocolHelper.MessageType.Literal);
// Send
_client.Send(command);
}
示例7: AddOrUpdateTaggedInterned
/// <summary>
/// Adds or updates the interned serialized objects in the cache at the given cache keys.
/// NOTE: interned objects use significantly less memory when placed in the cache multiple times however cannot expire or be evicted.
/// You must remove them manually when appropriate or else you may face a memory leak.
/// </summary>
/// <param name="cacheKeysAndSerializedObjects">The cache keys and associated serialized objects.</param>
/// <param name="tagName">The tag name.</param>
public void AddOrUpdateTaggedInterned(IEnumerable<KeyValuePair<string, byte[]>> cacheKeysAndSerializedObjects, string tagName)
{
// Sanitize
if (cacheKeysAndSerializedObjects == null)
{
throw new ArgumentNullException("cacheKeysAndSerializedObjects");
}
if (!cacheKeysAndSerializedObjects.Any())
{
throw new ArgumentException("must have at least one element", "cacheKeysAndSerializedObjects");
}
if (string.IsNullOrWhiteSpace(tagName))
{
throw new ArgumentException("cannot be null, empty, or white space", "tagName");
}
byte[] command = null;
using (var memoryStream = new MemoryStream())
{
memoryStream.WriteControlBytePlaceHolder();
memoryStream.Write("set-tag-intern {0}", tagName);
foreach (var cacheKeyAndSerializedObjectKvp in cacheKeysAndSerializedObjects)
{
memoryStream.WriteSpace();
memoryStream.Write(cacheKeyAndSerializedObjectKvp.Key);
memoryStream.WriteSpace();
memoryStream.WriteBase64(cacheKeyAndSerializedObjectKvp.Value);
}
command = memoryStream.ToArray();
}
// Set control byte
command.SetControlByte(DacheProtocolHelper.MessageType.RepeatingCacheKeysAndObjects);
// Send
_client.Send(command);
}
示例8: AddOrUpdate
/// <summary>
/// Adds or updates the serialized objects in the cache at the given cache keys.
/// </summary>
/// <param name="cacheKeysAndSerializedObjects">The cache keys and associated serialized objects.</param>
/// <param name="slidingExpiration">The sliding expiration.</param>
public void AddOrUpdate(IEnumerable<KeyValuePair<string, byte[]>> cacheKeysAndSerializedObjects, TimeSpan slidingExpiration)
{
// Sanitize
if (cacheKeysAndSerializedObjects == null)
{
throw new ArgumentNullException("cacheKeysAndSerializedObjects");
}
if (!cacheKeysAndSerializedObjects.Any())
{
throw new ArgumentException("must have at least one element", "cacheKeysAndSerializedObjects");
}
byte[] command = null;
using (var memoryStream = new MemoryStream())
{
memoryStream.WriteControlBytePlaceHolder();
memoryStream.Write("set {0}", (int)slidingExpiration.TotalSeconds);
foreach (var cacheKeyAndSerializedObjectKvp in cacheKeysAndSerializedObjects)
{
memoryStream.WriteSpace();
memoryStream.Write(cacheKeyAndSerializedObjectKvp.Key);
memoryStream.WriteSpace();
memoryStream.WriteBase64(cacheKeyAndSerializedObjectKvp.Value);
}
command = memoryStream.ToArray();
}
// Set control byte
command.SetControlByte(DacheProtocolHelper.MessageType.RepeatingCacheKeysAndObjects);
// Send
_client.Send(command);
}