Skip to content

Commit be92537

Browse files
authored
Merge pull request #24 from php-cache/namespace-doc
Added some docs about namespace
2 parents bbba4dc + b518ac6 commit be92537

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

docs/namespace.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Namespaced PSR-6 cache pool
2+
3+
The namespaced cache pool is a special cache of the hierarchical cache architecture where it only uses one level
4+
of hierarchy. Use this when you provide a third party library with a PSR-6 cache pool to make sure you never
5+
get key conflicts or unexpected calls to `CacheItemPoolInterface::clear()`.
6+
7+
```php
8+
// Get a pool that supports hierarchy
9+
$client = new \Redis();
10+
$client->connect('127.0.0.1', 6379);
11+
$pool = new RedisCachePool($client);
12+
13+
// Decorate it with a NamesapcedPool
14+
$namespacedPool = new NamespacedCachePool($pool, 'acme');
15+
16+
$item = $namespacedPool->getItem('foo')->set('bar');
17+
$namespacedPool->save($item);
18+
19+
$namespacedPool->hasItem('foo'); // True
20+
$pool->hasItem('foo'); // False
21+
```
22+
23+
Internally the `NamespacedCachePool` will prepend all keys with `|acme|`. Which means that the `$pool`
24+
may access items in the namespace by doing the very same:
25+
26+
```php
27+
$pool->hasItem('|acme|foo'); // True
28+
```
29+
30+
## Symfony integration
31+
32+
If you are are using our bundles you may configure a service with as a namespaced pool by using the `pool_namespace`
33+
configuration option.
34+

0 commit comments

Comments
 (0)