views:

32

answers:

0

I'm wondering about managing collections of data in memcached. I'm confused about how I maintain cache freshness/integrity when I have many levels of caching at work. Let's assume I have a hierarchy of cached data objects, for example,

A represents the most atomic element of data,
B represents a collection of 10 As
C represents a collection of 10 Bs
[…]

So, my question: If I have an update to one atomic object, say A[5], that dirties a set of cached objects, say { B[3] , B[6] , C[21], C[25], A[4] }, how do I record these relationships inside of memcached in a thread-safe way?

I'm leaning toward having comma-separated _rel objects for each cache object that enumerate the relationships that comprise that cached object. I guess I would update those through a memcached append() to ensure thread safety, but memcached doesn't seem to have a baked-in thread-safe method to remove key references from a relationship value at scale and concurrency. (I'm worried that the contention from many distributed nodes updating to the same relationship element could undermine integrity if writes were slightly asynchronous, eg, slight network blips. And if I don't remove relationships, I could end up with HUGE relationship dependencies that undermine caching to begin with. )

Sorry if this is a memcached n00b question, but I can't seem to find much more than confusion regarding the management of collections in memcached.

Any guidance would be awesome! TIA!