PHP code example of groupbuy / hyperf-memory-cache
1. Go to this page and download the library: Download groupbuy/hyperf-memory-cache 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/ */
groupbuy / hyperf-memory-cache example snippets
use Groupbuy\HyperfMemoryCache\Annotation\MemoryCache;
class ConfigService
{
#[MemoryCache(key: 'cfg:{sid}:{column}', ttl: 30)]
public function getConfig(string $sid, string $column): array
{
return Db::table('shop_config')->where(...)->get()->toArray();
}
}
use Groupbuy\HyperfMemoryCache\Annotation\MemoryCacheEvict;
class ConfigService
{
#[MemoryCacheEvict(key: 'cfg:{sid}:{column}')]
public function setConfig(string $sid, string $column, array $cfg): void
{
Db::table('shop_config')->where(...)->update($cfg);
}
}