0

The value that I'm trying to append to is a string. I've been able to convert the string to a byte array using Encoding.ASCII.GetBytes(value) and passing that to the IMemcachedClient:

Appending to Memcached (seems fine)

var value = "Some string value that should get appended";
var bytes = Encoding.ASCII.GetBytes(value);
_memcachedClient.Append(key, new ArraySegment<byte>(bytes, 0, bytes.Length));

Getting appended value from Memcached

var valueAsBase64 = _memcachedClient.Get(key) as string;
var bytes = System.Convert.FromBase64String(valueAsBase64);
var result = Encoding.ASCII.GetString(bytes);

I see the value returned, and it's a string. I'm just not sure how to get the value returned back to the string I started off with (now appended).

BlackjacketMack
  • 5,472
  • 28
  • 32

1 Answers1

0

The issue I was running into was that I simply was initializing the entry with an empty string instead of an empty byte array. So the return type was a mangled mismash.

The issue came down to the .Append() method not setting an initial value if the key doesn't exist. I'll look a little more into it to see if there's a way of having it do an initial Put if the key doesn't exist.

This works though:

var bytes = (byte[])_cache.Get(key);
var value = Encoding.ASCII.GetString(bytes);
BlackjacketMack
  • 5,472
  • 28
  • 32