I'm writing code to remove a cache entry from non-Azure AppFabric (v1.1). In the code snippet below, DataCache.Remove is always returning false...
object bogusData = new object();
_cache.Put(account, bogusData, TimeSpan.FromSeconds(10.0));
Sleep(1000); // for testing purposes
// we don't need the contents of the cache entry, we just want to know
// if the account is in the cache or not...
object cachedData = _cache.Get(account);
// if we don't find it in the cache, it is already been removed (or expired), so return true.
if (cachedData == null)
return true;
Sleep(1000); // for testing purposes
// this always returns false
bool status = _cache.Remove(account);
By design, in the above code snippet, cachedData is always != null.
Any ideas?
Woot!
I figured it out, calling DataCache.Remove(key) will attempt to remove the item from the default region. While, not clearly shown above (_cache is a thin wrapper around DataCache), our Put/Get calls include a region name, but our Remove did not. I added the Region and the Remove worked properly.