Archive for the ‘memcache’ tag
Memcache++ no comments
Memcache has been a core part of my web programming lately and it’s one of the most flexible and useful systems ever come across.
Think for a second about the process when two people request the same dynamic page on a website. The code rendering one request has no idea that there is another request for the same page so effectively you do the whole process twice. Let’s also imagine that this request pulls a huge list of data out of a massive table that takes a while to query. In an ideal world the dbms should cache the query and the second request should be faster. In reality, and with a simple dbms both sets of data are returned in the same time. Now say one hundred other people also request that same page over the next few minutes, are we going to keep calling that data out of the database from the hard disk or is there a better way?
This is where memcache comes into it’s own. If, after pulling the data out of the database, it is placed in memory and not destroyed after the page is rendered it can be retrieved next time we want the same data. Hey presto, we can now serve thousands more requests per second as we are no longer asking for data from the database, we have exactly what we want waiting in memory.
Memcache isn’t without it’s problems, what if we change what’s in the database. Our version in memcache is now out of date. Thankfully we have set an expiry time on things that we give to memcache, so it falls out of memory after a period of time. What if your data is time sensitive? As with many things I am working on it is important that things happen at certain times rather than just waiting for things to fall out of memory. This is one problem I am currently working on and something I will cover in future.