1. Go to this page and download the library: Download webiny/hrc library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webiny / hrc example snippets
// define cache rules
$cacheRules = [
'FooBar' => [
'Ttl' => 60,
'Tags' => ['cacheAll'],
'Match' => [
'Url' => '*'
]
]
];
// where and how to store cache files
$cacheStorage = new Webiny\Hrc\CacheStorage\FileSystem('/path/to/cache/folder/');
// where and how to keep a record of all stored cache files
$indexStorage = new Webiny\Hrc\IndexStorage\FileSystem('/path/to/index/folder');
// create Hrc instance
$hrc = new Hrc($cacheRules, $cacheStorage, $indexStorage);
// store something into cache
$hrc->save('entryName', 'some content');
// retrieve something from cache
$data = $hrc->read('entryName'); // some content
class MockCallbacks
{
public static function returnTrue(Webiny\Hrc\Request $r, Webiny\Hrc\CacheRules\CacheRule\CacheRule $cr)
{
// do you thing here
}
}
// use the first matched cache rule
$hrc->save('entryName', 'some content');
$data = $hrc->read('entryName');
// use fooBar cache rule
$hrc->save('block 122', 'some content', 'fooBar');
$data = $hrc->read('block 122');
// your Hrc instance
$hrc = new Hrc($cacheRules, $cacheStorage, $indexStorage);
// my callback handler -> must implement \Webiny\Hrc\EventCallbackInterface
$handler = new MyCallbackHandler();
// register callbacks
$hrc->registerCallback($handler);
// save the cache and get back the cache key
$key = $hrc->save('entryName', 'some content');
// purge that cache entry
$hrc->purgeByCacheKey($key);
$hrc->purgeByTag(['tag1', 'tag2']);
// first set the purge flag to true
$hrc->setPurgeFlag(true);
// once the flag is set to true, every `read` call, that has a cache hit, will actually do a purge
$hrc->read('entryName');
// set the control header
$hrc->setControlKey('someSecretString');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.