Yet another cache for hyperf.

2.0.1 2021-07-02 01:02 UTC

This package is auto-updated.

Last update: 2021-12-02 02:15:33 UTC


README

Latest Stable Version Total Downloads GitHub license

Yet Another Hyperf Cache

Installation

  • Request
composer require friendsofhyperf/cache

Usage

  • Inject
namespace App\Controller;

use FriendsOfHyperf\Cache\CacheInterface;
use Hyperf\Di\Annotation\Inject;

class IndexController
{
    /**
     * @Inject
     * @var CacheInterface
     */
    private $cache;

    public function index()
    {
        return $this->cache->remember($key, $ttl=60, function() {
            // return sth
        });
    }
}
  • Facade
use FriendsOfHyperf\Cache\Facade\Cache;

Cache::remember($key, $ttl=60, function() {
    // return sth
});
  • Switch driver
use FriendsOfHyperf\Cache\Facade\Cache;
use FriendsOfHyperf\Cache\CacheManager;

Cache::driver('co')->remember($key, $ttl=60, function() {
    // return sth
});

CacheManager::get('co')->remember($key, $ttl=60, function() {
    // return sth
});

Methods

Likes Laravel-Cache