Skip to content

Commit c6e3c5d

Browse files
committed
readme
1 parent ebcf742 commit c6e3c5d

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

README.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,7 +2930,8 @@ $collection->find()->where('field', 1)->hind(array('field' => 1));
29302930
Caching and documents with TTL
29312931
------------------------------
29322932

2933-
If you want to get collection where documents will expire after some specified time, just add special index to this collection.
2933+
If you want to get collection where documents will expire after some specified time,
2934+
just add special index to this collection.
29342935

29352936
```php
29362937
<?php
@@ -2940,14 +2941,19 @@ $collection->ensureTTLIndex('createDate', 1000);
29402941
You can do this also in migration script, using [Mongo Migrator](https://github.com/sokil/php-mongo-migrator).
29412942
For details see related documentation.
29422943

2943-
Or you can use `\Sokil\Mongo\Cache` class, which already implement this functionality.
2944+
You also can use `\Sokil\Mongo\Cache` class, which already implement this functionality and compatible with PSR-16 interface.
29442945

29452946
```php
29462947
<?php
2948+
29472949
// Get cache instance
2948-
$cache = $document->getCache('some_namespace');
2950+
$cache = $database->getCache('some_namespace');
29492951
```
2950-
Before using cache must be inititalised by calling method `Cache:init()`:
2952+
2953+
Namespace is a name of collection to be created in database.
2954+
2955+
Before use cache must be initialised by calling method `Cache:init()`:
2956+
29512957
```php
29522958
<?php
29532959
$cahce->init();
@@ -2965,24 +2971,21 @@ db.some_namespace.ensureIndex('e', {expireAfterSeconds: 0});
29652971
Now you can store new value with:
29662972
```php
29672973
<?php
2968-
// this store value for 10 seconds by defininc concrete timestamp when cached value expired
2969-
$cache->setByDate('key', 'value', time() + 10);
2970-
// same but expiration defined relatively to current time
2974+
// this store value for 10 seconds
2975+
// expiration defined relatively to current time
29712976
$cache->set('key', 'value', 10);
29722977
```
29732978

2974-
You can devine value which never expired and must be deleted manually:
2979+
You can define value which never expired and must be deleted manually:
29752980
```php
29762981
<?php
2977-
$cache->setNeverExpired('key', 'value');
2982+
$cache->setNeverExpired('key', 'value', null);
29782983
```
29792984

29802985
You can define some tags defined with key:
29812986
```php
29822987
<?php
29832988
$cache->set('key', 'value', 10, ['php', 'c', 'java']);
2984-
$cache->setNeverExpired('key', 'value', ['php', 'c', 'java']);
2985-
$cache->setDueDate('key', 'value', time() + 10, ['php', 'c', 'java']);
29862989
```
29872990

29882991
To get value

src/Cache.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ class Cache implements \Countable, CacheInterface
2222
const FIELD_NAME_TAGS = 't';
2323

2424
private $collection;
25-
25+
26+
/**
27+
* Cache constructor.
28+
* @param Database $database
29+
* @param string $collectionName namespace of cache
30+
*/
2631
public function __construct(Database $database, $collectionName)
2732
{
2833
$this->collection = $database

src/Database.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,9 @@ public function getQueue($channel)
423423
/**
424424
* Get cache
425425
*
426-
* @param string $namespace
427-
* @return \Sokil\Mongo\Cache
426+
* @param string $namespace name of collection to be created in database
427+
*
428+
* @return Cache
428429
*/
429430
public function getCache($namespace)
430431
{

0 commit comments

Comments
 (0)