[ic] Interchange and memcached

Ethan Rowe ethan at endpoint.com
Wed Sep 17 14:38:41 UTC 2008


Doug Whiteley wrote:
> Has anyone had a play around at getting interchange to use memcached 
> (http://www.danga.com/memcached/) yet?

Yes.  We're working on that right now, actually, though it's in a highly
customized situation that doesn't lend itself to contribution to the
community, unfortunately.  It's in a codebase that is basically pure
Perl using Moose and Rose::DB::Object that happens to run within
Interchange, rather than anything using particularly idiomatic to
Interchange.

However, it's pretty simple.  Implementing a custom usertag to act like
timed-build but using memcached instead of the filesystem would really
be fairly trivial.  That's just for basic single-cache-resource operations.

One thing that's tricky, though, is that memcached cached objects are
limited in size (1 Meg by default).  This means when caching large sets
of data, you're better off caching a list of ids that refer to
individual object caches.  You then fetch those object caches by their
ids.  Memcached lets you do bulk get/set/add/replace operations to
optimize the I/O, which is important.  But designing a usertag interface
to this kind of operation would probably be difficult and fairly
unsatisfying.

IC's native caching (timed build) is all about building on demand and
expiring in regular intervals.  Memcached supports that approach, but
that's not the optimal usage pattern.  Because memcached is distributed
and shared by any number of clients (as opposed to a cache on a local
file system), you can use a much more scalable and powerful approach:
when changing state for a resource in the database, update the cached
representation of that resource in memcached.  Thus the cache is written
during the already-more-expensive write operation, reads are fast and
cheap, and the cache is (nearly) always immediately up to date.  When
you're dealing with apps that run on multiple servers, the scalability
benefits of this approach are significant.

-- 
Ethan Rowe
End Point Corporation
ethan at endpoint.com



More information about the interchange-users mailing list