Sunday, April 06, 2008

Memcached for Monorail Update

Memcached for Monorail (MfM) is my attempt at a simple, memcached/enyim based, session and caching facility for Monorail. MfM offers a lightweight, fast, low friction, facility for balancing Monorail sessionstate and object caches accross multiple servers. You can read my original post.

Memcached offers an excellent solution for applications that need to balance object caches across multiple servers. It does so without the overhead of a database or even the use of the hard disk. Although, a major pitfall for memcached is it's unreliable nature. If a server in your memcached cluster fails then you lose all the objects cached on it. Memcached is just not meant for persisting object data permanently.

The current release of MfM is capable of persisting sessionstate to a memcached cluster. If one or more memcached servers fails then that part of the session will be lost, permanently. For my projects, I found this unacceptable. I decided to add a DB persistence layer using ActiveRecord.

I just started adding the database persistence layer to the custom session factory. My plan is to use ActiveRecord for the persistence. This will allow MfM to leverage the crossplatform support already built into ActiveRecord. Here is the psudo-logic I plan to implement:

If Writing to the Session then Write value to DB AND
delete the object stored on the Memcached Cluster.

If Reading from then Session then retrieve from Memcached Cluster OR
if value doesn't exist in Cluster then retrieve value from DB AND
write the value to the Memcached Cluster.

I imagine I will want to implement some kind of locking.

To learn more check out the project website. You can also browse the source repository or checkout the code yourself.

2 comments:

Anonymous said...

Stumbled across your post while debugging a bug with my current implementation.

Memcached is just phenomenal. I'll test your implementation in the coming days and post some feedback.

Thanks!

Aadhya said...

Myself so glad to establish your blog entry since it's actually quite instructive. If it's not too much trouble continue composing this sort of web journals and I normally visit this blog. Examine my administrations.
Go through these Salesforce Lightning Features course. Found this Salesforce CRM Using Apex And Visualforce Training worth joining. Enroll for SalesForce CRM Integration Training Program and practice well.