PHPackages                             treasure-chest/treasure-chest - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. treasure-chest/treasure-chest

ActiveLibrary[Caching](/categories/caching)

treasure-chest/treasure-chest
=============================

A simple key/value store with namespace support and backends for memcached, apc, and more.

0.1.5(13y ago)34.7k1MITPHPPHP &gt;=5.3.0

Since Oct 8Pushed 12y ago1 watchersCompare

[ Source](https://github.com/jamesmoss/treasure-chest)[ Packagist](https://packagist.org/packages/treasure-chest/treasure-chest)[ Docs](http://github.com/jamesmoss/treasure-chest)[ RSS](/packages/treasure-chest-treasure-chest/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (5)Used By (1)

TreasureChest
=============

[](#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
------------

[](#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
------------

[](#installation)

Use [Composer](http://getcomposer.org/) to install the `treasure-chest/treasure-chest` package. Package details [can be found on Packagist.org](https://packagist.org/packages/treasure-chest/treasure-chest).

Add the following to your `composer.json` and run `composer install` (or `composer update`).

```
"require": {
    "treasure-chest/treasure-chest": "0.1.*"
}

```

Usage
-----

[](#usage)

Create an instance of the `TreasureChest\Instance` class, passing in an instance of the datastore you wish to use.

```
$bounty = new \TreasureChest\Instance(new \TreasureChest\Cache\APC);
```

Use the `add`, `store`, `fetch`, `replace`, `exists`, `inc`, `dec` and `delete` methods to store, retrieve and manipulate your data. e.g

```
$bounty->store('email', 'bob@example.org');
$bounty->store('age', 45);
$bounty->fetch('email'); // returns bob@example.org
$bounty->inc('age', 5); // returns 50
$bounty->dec('age', 10); // returns 40
$bounty->delete('email');
$bounty->fetch('email'); // returns boolean FALSE
```

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

```
$bounty->add('user123:username', 'bob');
$bounty->add('user123:email', 'bob@example.org');
$bounty->add('user123:age', 21);

// Clear the entire user123 namespace
$cache->invalidate('user123');

$cache->fetch('user123:username'); // returns boolean FALSE
$cache->fetch('user123:email'); // returns boolean FALSE
$cache->fetch('user123:age'); // returns boolean FALSE
```

Known issues
------------

[](#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
-----

[](#to-do)

- Introduce option to check namespace version before every cache call.
- Improve testing suite. Expand current PHPUnit tests to cover more code.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~36 days

Total

4

Last Release

4854d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c8df8042707f8b81f8e3e27f368db711ac8f87f5f3cc1e9ade4c6cf32e34a7db?d=identicon)[jamesmoss](/maintainers/jamesmoss)

---

Top Contributors

[![jamesmoss](https://avatars.githubusercontent.com/u/629766?v=4)](https://github.com/jamesmoss "jamesmoss (8 commits)")

---

Tags

cachecachingmemcachedapc

### Embed Badge

![Health badge](/badges/treasure-chest-treasure-chest/health.svg)

```
[![Health](https://phpackages.com/badges/treasure-chest-treasure-chest/health.svg)](https://phpackages.com/packages/treasure-chest-treasure-chest)
```

###  Alternatives

[tedivm/stash

The place to keep your cache.

9824.8M124](/packages/tedivm-stash)[tedivm/stash-bundle

Incorporates the Stash caching library into Symfony.

841.4M16](/packages/tedivm-stash-bundle)[sabre/cache

Simple cache abstraction layer implementing PSR-16

541.2M3](/packages/sabre-cache)[jamm/memory

Key-value storage in memory. As a storage can be used: APC, Redis, Memcache, Shared memory. All storage objects have one interface, so you can switch them without changing the working code. Contains PHP Redis client.

13326.3k1](/packages/jamm-memory)[alekseykorzun/memcached-wrapper-php

Optimized PHP 5 wrapper for Memcached extension that supports dog-piling, igbinary and local storage

2984.6k1](/packages/alekseykorzun-memcached-wrapper-php)[ihor/cachalot

Cache a lot in a proper way (APC, XCache, Memcached, Redis, Couchbase)

2528.1k](/packages/ihor-cachalot)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
