memcached counters missing in action
brad at danga.com
Fri Mar 24 19:18:57 UTC 2006
What's a counter?
memcached has no such object.
I assume the Java client gives you such an abstraction. In any case,
they're not magic. They die like the rest.
On Fri, 24 Mar 2006, Charlie Spurr wrote:
> I'm using memcached counters to track budget balances and
> I'm seeing some of the counters mysteriously disappear
> from the cache sometime after a decr of the counter.
> Here's what I'm doing for each counter:
> a) At application startup on the primary app server, I
> load the current remaining balance for each budget
> from a MySQL database into a memcached counter using
> the Java MemCachedClient's storeCounter(String key,
> long value) method.
> b) As billable events occur asynchronously, I call the client's
> decr(String key, long amount) method to decrement the
> remaining balance in the cache.
> c) In a synchronization thread (one per app server, ten total),
> I call the MemCachedClient's getCounter(String key) method
> to retrieve the cached budget balance and sync it back to
> the database.
> This seems to run fine for a while until getCounter or decr calls
> start to hit "MemCached.MemCachedClient - counter not found at key:"
> errors. When this occurs, MemCachedClient's keyExists(String key)
> calls return true but getCounter or decr calls fail with this error.
> My questions are:
> 1) Do counters expire like Object data expire or are they expected
> to remain in the cache until they are deleted or flushed?
> 2) If counters expire, how do I set their expiration time? There is no
> version of MemCachedClient's storeCounter that takes a expire Date
> parameter. Should I be using MemCachedClient's set(String key,
> Object value, Date expiry) instead of (or in combination with)
> 3) Shouldn't MemCachedClient's keyExists(String key) return false
> when calls to getCounter or decr calls fail with "counter not
> found at key:" errors?
> Charlie Spurr
More information about the memcached