@@ -2930,7 +2930,8 @@ $collection->find()->where('field', 1)->hind(array('field' => 1));
2930
2930
Caching and documents with TTL
2931
2931
------------------------------
2932
2932
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.
2934
2935
2935
2936
` ` ` php
2936
2937
<?php
@@ -2940,14 +2941,19 @@ $collection->ensureTTLIndex('createDate', 1000);
2940
2941
You can do this also in migration script, using [Mongo Migrator](https: // github.com/sokil/php-mongo-migrator).
2941
2942
For details see related documentation.
2942
2943
2943
- Or you can use ` \S okil\M ongo\C ache` class , which already implement this functionality.
2944
+ You also can use ` \S okil\M ongo\C ache` class , which already implement this functionality and compatible with PSR - 16 interface .
2944
2945
2945
2946
` ` ` php
2946
2947
<?php
2948
+
2947
2949
// Get cache instance
2948
- $cache = $document ->getCache('some_namespace');
2950
+ $cache = $database ->getCache('some_namespace');
2949
2951
` ` `
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
+
2951
2957
` ` ` php
2952
2958
<?php
2953
2959
$cahce->init();
@@ -2965,24 +2971,21 @@ db.some_namespace.ensureIndex('e', {expireAfterSeconds: 0});
2965
2971
Now you can store new value with:
2966
2972
` ` ` php
2967
2973
<?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
2971
2976
$cache->set('key', 'value', 10);
2972
2977
` ` `
2973
2978
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:
2975
2980
` ` ` php
2976
2981
<?php
2977
- $cache->setNeverExpired('key', 'value');
2982
+ $cache->setNeverExpired('key', 'value', null );
2978
2983
` ` `
2979
2984
2980
2985
You can define some tags defined with key:
2981
2986
` ` ` php
2982
2987
<?php
2983
2988
$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']);
2986
2989
` ` `
2987
2990
2988
2991
To get value
0 commit comments