Download the PHP package treasure-chest/treasure-chest without Composer
On this page you can find all versions of the php package treasure-chest/treasure-chest. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download treasure-chest/treasure-chest
More information about treasure-chest/treasure-chest
Files in treasure-chest/treasure-chest
Package treasure-chest
Short Description A simple key/value store with namespace support and backends for memcached, apc, and more.
License MIT
Homepage http://github.com/jamesmoss/treasure-chest
Informations about the package treasure-chest
TreasureChest
A simple key/value store with namespace support and backends for memcached, apc, filesystem and more.
TreasureChest's biggest feature is namespaces. Most existing key/value stores place your data in a single global environment, this can lead to clashing key names in large datasets. They also don't support wildcards when deleting keys. It's impossible to do something like store('user1_username', 'bob')
and then delete('user1_*');
. This makes tracking and invalidating large sets of related keys difficult. TreasureChest provides a wrapper around your favourite key/value store (memcached, apc, xcache etc) making this possible.
Internally, TreasureChest uses a pointer which keeps track of the version number of each namespace. This version number is prefixed to all keys which get passed into the class. When a namespace is invalidate
ed the pointer is incremented by 1, thereby changing the key which gets passed to the datastore.
Requirements
- PHP 5.3 or higher
- Composer
- APC 3.1.1 or higher (if using APC as backend)
- Memcached 1.2.0 and PECL memcached 0.1.0 or higher (if using Memcached as backend)
Installation
Use Composer to install the treasure-chest/treasure-chest
package. Package details can be found on Packagist.org.
Add the following to your composer.json
and run composer install
(or composer update
).
"require": {
"treasure-chest/treasure-chest": "0.1.*"
}
Usage
Create an instance of the TreasureChest\Instance
class, passing in an instance of the datastore you wish to use.
Use the add
, store
, fetch
, replace
, exists
, inc
, dec
and delete
methods to store, retrieve and manipulate your data.
e.g
Namespaces can be used to logically group sets of key/value pairs. Simply append the key with the desired namespace, separated by a colon (this delimiter character can be changed) e.g
Known issues
There is currently a concurrency issue which can lead to TreasureChest returning data which should have been invalidated. This happens if another PHP process calls invalidate
whilst the first process is still running. This could be fixed by checking the namespace version number before each call to fetch
, store
etc. This has a performance impact so I'll be making it a user enabled option.
To do
- Introduce option to check namespace version before every cache call.
- Improve testing suite. Expand current PHPUnit tests to cover more code.