Introduction
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.
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.
Since the Monorail sessions exist independent of the ASP.Net session the ASP.Net session can be used to persist values locally...this gives a noticeable read performance.
Use Scenarios
- Monorail based web application load balanced on multiple servers needs a fast efficient way of sharing session state without the overhead of constantly reading a database.
- More Anyone?
Details
Caching Strategy
This library is READ optimized. As long as memcached stays un-flushed your app should never read from the database. Write speeds depend on the speed of your db server. You have 3 options for persisting to the database;(1)No db persistence, (2)Active record persistence (3) raw persistence.
WRITING
- From the beginning of an action to the end values are stored in the ASP.Net session.
- Once the action ends (and persist is called by the session factory) Values that changed are then persisted to memcached and the database (if turned on)
- Timestamps are stored to check for staleness at the begining of each session.
READING
- The session first checks that the ASP.Net session is not stale. Uses the ASP session if the key exists and it isn't stale.
- If this fails then memcached is checked...values are then persisted to the local ASP session.
- If memcached fails then the database is checked. Values are persisted to both the local session and memcached.
- If the database fails then the key is assumed to not exist and null is returned.
Dependencies
Here are a few dependencies you will need to get going:
- Castle::Monorail
- A memcached server or servers running on your network. Here are some windows ports:
- The latest release of Enyim.
- If you want to run the tests or plan on making modifications then you will need the Nunit/RhinoMocks stack.
OK, It's late at night and this is an eleventh hour post. I promise more information in the next few days!
Current Features
- A session dictionary that uses memcached on the backend
- Fully implemented IDictionary (The Values property and enumeration are not implemented)
- ICustomSessionFactory for CASTLE::MONORAIL
- Now has the ability to use a DB backend
- Uses a local temp hashtable to speed up access to commonly accessed session variables.
- Alternatively you can pass in the local ASP.Net session for additional speed increase. The session dictionary will automatically handle staleness across the cluster.
Planned Features
- Optional DB persistence of sessions using activerecord/memcached fusion.
- Move all configuration to a single MemcachedForMonorail configuration file.
- Reconsider or Refactor the enumeration stuff in the IDict impl
- Persist the hashtable locally using the underlying session to reduce memcached hits...
- Config options for lazy loading or not lazy loading
- Uh...some build scripts.
- Cache provider for monorail.
- Cache provider integration with ActiveRecord.
Limitations
Memcached does not replicate cached objects across all servers. It simply load balances them. That said, until I add the DB persistence your application will be vulnerable to losing some session values if one or more memcached server goes down.