Well, I see that you are looking for Memcached. This product makes things exactly as you wish, is free and stable. Used by Wikipedia and others. If you want to do your own, you can take a look to its doc when It's explainedit's documentation where the way it works is explained.