There is a new and better version of this memcached clone. Please check out depcached. The mmcached software is not maintained anymore.
Memcached is a high-performance, distributed memory object caching system. It is created and maintained by Danga Interactive. I adapted memcached 1.1.12 so that it supports a directory like structure for keys. I also added an option to prevent particular keys to be flushed, making them persistent during the specified caching period.
When using memcached for multiple sites we ran into the problem that:
Why would we want to flush different categories? An easy example is when you change a page template, in that case you want to flush everything that uses that template, but not all cached objects, configuration details, sessions etc.
We were able to use the same memcached daemons by prefixing all keys with the database name of the site. This is possible because every site is using an unique database. For example, the key config will become something like any_mms05/config.
Solving the requirement of flushing only parts of the cache, without deleting specific keys was a bit harder. I needed to change the code of memcached; open source comes to the rescue.
I added hierarchy to the cached keys by splitting the keys on /-characters. Each key can have any number of /-characters, creating multiple levels of hierarchy.
For every element in the path of the key we store a timestamp. When the timestamp of a path-element (directory) is newer that the timestamp of the key (file) then the key is considered to be invalid.
For every cache lookup I split the key in its list of path-elements. For every level we check the timestamp of the different levels. This is done very fast (O(n) where n is the number of levels) by using a separate hash table, which is never flushed. The maximum timestamp is then compared against the timestamp of the cache entry.
For example database/object/thing/1004, will be have modification checks on database, database/object and database/object/thing.
One of the nice things of the memcached is that it is a very fast object store, much faster than a database. This makes it very attractive as a versatile data store. Of course memcached is a cache. So there is no guarantee that the data stored will be retained till the given expiration time. Memcached has an option to prevent flushing of data when memory is exhausted. However, this is a global switch. More useful would be to be able to specify on a item-by-item basis which stored elements might be flushed and which not.
I changed memcached so that you can specify if an item might be flushed, or should be kept till its expiration time (or till it is flushed manually). This is done by adding an exclamation character at the end of the key, for example: database/presence/queue!
Please note that database/presence/queue! and database/presence/queue are two different keys. The exclamation mark is part of the key name, this to prevent problems with existing code.
Of course, data will still be flushed when memcached is restarted, or when the key is deleted.
You can download the modified memcached mmcached and a modified php memcache extension. The modified php extension has an additional function flush_dir($dir). This function can be used for invalidating keys stored below the given directory.
More information about memcached can be found at www.danga.com/memcached/
A manual page of the PHP extension memcache is at nl2.php.net/memcache
When using memcache we bumped into some problems. The major one was that we needed to invalidate...
All Internet applications have to secure their inner workings against attacks from outside. We a...
Here is the full implementation of OAuth for anyMeta. For now we...
Verso Wiki is a Wiki to HTML and HTML to Wiki markup translator. We use this W...
A PHP library for OAuth consumers and servers. Complete with an extensible OAuth store, includi...
I just published a new version of our OAuth server and consumer code. The major addition to thi...
The PHP JPEG metadata toolkit is a rather complete library to read the EXIF data from digital cam...
Everyone uses different ways to format their code. And everyone has very good reasons to do it hi...
When using memcache we bumped into some problems. The major one was that we needed to invalidate...
A PHP library for OAuth consumers and servers. Complete with an extensible OAuth store, includi...
I just published a new version of our OAuth server and consumer code. The major addition to thi...
When using memcache we bumped into some problems. The major one was that we needed to invalidate...
I just tagged anyMeta 3.2.3. It is a small version number change that incorporates big changes u...
Danga.com is a group of programmers, sysadmins, and designers developing and running community-ce...
Here is the full implementation of OAuth for anyMeta. For now we...
A PHP library for OAuth consumers and servers. Complete with an extensible OAuth store, includi...
I just published a new version of our OAuth server and consumer code. The major addition to thi...