How to make SQLAlchemy use Memcached?
Has anyone joined SQLAlchemy and Memcached together so that results returned by SQLAlchemy where cached in Memcached? At the moment开发者_JAVA百科 I have no idea how to implement it myself, I am completely lost and looking for help.
Thanks, Boda Cydo.
See the beaker caching example in SQLAlchemy source to see how you might integrate caching into a SQLAlchemy application. Beaker can use Memcached as the cache store.
Memcache and relational databases are two separate things, that don't work in the same way at all. Memcache is a simple lookup bucket, useful for dumping blobs like partial web pages in that are shared amongst many requests and take you a long time to produce (for when you can't reasonably optimise/denormalise your database schema enough to make them quick to produce).
It's not a good idea to use memcache like a full backend data store, and it wouldn't be useful to present an SQL interface that went to memcache or the database: you'd get the worst of both worlds, without either memcache's simplicity/speed or a relational database's ACID-compliance.
Your database server already has a cache. If you want it to cache more, turn the size of that cache up as high as you can without having to go to silly hardware. Use memcache for making the front-end faster — but only when you really can't get the performance you want out of the database, because it requires you to make compromises on data consistency. Don't resort to memcache until you really need to.
精彩评论