The title of this question might be confusing but the problem is simple.
I’m using Zend_Cache with memcached as a backend. I have two module called “Last articles” and “Popular articles”. Both of this module are on every pages and use a similar query such as :
Select * from table where status = 'published' and category = '' order by dateCreated|/popularity\
My table have 1.5 million rows so far. I have indexes on every field that I’m using in the previous query.
I cache the recent articles for 1hour and the popular for 4hours. I have 4 web server (php5/apache2) and 1 database server (mysql). The table engine is innoDB.
The problem some time my cache expire right in the middle of a heavy load, which make my web site unavailable until those modules are cached again. I could had a new MYSQL server.
But is there a way to handle the caching in a smarter way? Like for example the server1 will try to refresh the cache while server 2,3 and 4 will still use the same value out of the cache.
I can write some code to do that, but I was wondering if there is way to do that directly with Zend_Cache? Of if there is a design pattern that i could apply to my problem?
[EDIT] I want something that I could scale up to 100 servers
I finally implemented a class that inherit from Zend_Cache_Backend_Libmemcached
I’m overriding the load() method.
Each of my server has there hostname finishing by a set of number such as serv01, serv02, serv03, serv04.
The main idea is taht each server will think that the cache expired at different time. For example serv01 will think that the cache is expired 20minutes before it actually expires, serv02 will be 15minutes, serv03 10minutes and serv04 5minutes.
By doing so my cache will never be refresh at the same time on each server, and if one server is down the cache will be refresh by another server.