Created
November 17, 2016 07:19
-
-
Save shadiakiki1986/4d6a1b01f1237d6a3f2bab0b8c2e6463 to your computer and use it in GitHub Desktop.
Example usage of https://github.com/php-cache/filesystem-adapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "root/test-phpcache-filesystem", | |
"require": { | |
"cache/filesystem-adapter": "^0.3.2" | |
}, | |
"authors": [ | |
{ | |
"name": "Shadi Akiki", | |
"email": "shadiakiki1986@gmail.com" | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'vendor/autoload.php'; | |
use League\Flysystem\Adapter\Local; | |
use League\Flysystem\Filesystem; | |
use Cache\Adapter\Filesystem\FilesystemCachePool; | |
$filesystemAdapter = new Local(__DIR__.'/'); | |
$filesystem = new Filesystem($filesystemAdapter); | |
$pool = new FilesystemCachePool($filesystem); | |
// test get null | |
var_dump($pool->getItem('bla.txt')->get()); | |
// test set | |
$ttl = new \DateInterval('PT1S'); | |
$item = $pool->getItem('bla.txt')->set('some content')->expiresAfter($ttl); | |
$pool->save($item); | |
// test get after set | |
var_dump($pool->getItem('bla.txt')->get()); | |
// sleep 1 sec | |
sleep(2); | |
var_dump($pool->getItem('bla.txt')->get()); | |
var_dump('test remove'); | |
$item = $pool->getItem('bla.txt')->set('some content'); | |
$pool->save($item); | |
var_dump($pool->getItem('bla.txt')->get()); | |
$pool->deleteItem('bla.txt'); | |
var_dump($pool->getItem('bla.txt')->get()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment