Hello, I am building a site that needs to handle a lot of traffic (thousand requests per second), so I want to have a high performance system. I plan on using mysql as the backend store and memcache as the caching layer. It looks like Zend_Db and Zend_Cache will be perfect for this. There are some ways I am thinking of implementing it and was wondering if anyone had best practices or an approach they really like. Just to have an example to work with, say I have a library of books that I want to allow users to browse. All the book information will be in a mysql table and a class Book that will have functions like getTitle, getAuthor, etc... The idea would be to check the memcache for the book and if it exists use the information in the cache, if it doesn't exist get it from the mysql database and then store it in memcache. If there are any updates or new books, expire the cache.
Here are some approaches I was thinking.... 1) Create a class Book that extends Zend_Db_Table_Abstract which will allow easy access to the book table in the database. Then have a Factory that I will ask for a book object. The factory will check the memcache first to see if it exists and if so, then return the object from the memcache (using serialization to store it). If it doesn't exist, create a new instance of the Book object, store it in memcache and then return it to the caller. The drawback with this approach is i have found that serialize and unserialize is slow with objects especially if they have a lot of member variables (remember, I need to have this HIGHLY optimized). 2) Create a class Book that doesn't extend anything. In the constructor, it will check the memcache to see if all the data is populated already, like title, author, etc.. and if so, then do nothing. If not, then make the sql queries to get the data and populate the key/value pairs into memcache (instead of a big hash or object that has to be serialized/unserialized). Whenever you call $book->getTitle(), it will do a $cache->get( 'title' ). fyi - not exact syntax. 3) other? Essentially, the idea is to have LOTS of memory to store LOTS of books using memcache, so access is quick. Should I store the entire book object in memory or just the data which the object can retrieve? Thanks, Shawn
