PHP code example of crack9527 / swoft-cache

1. Go to this page and download the library: Download crack9527/swoft-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/ */

    

crack9527 / swoft-cache example snippets


cache()->get($key);
 php
 declare(strict_types=1);

namespace App\Http\Controller;

use Crack9527\Cache\Contract\CacheInterface;
use Swoft;
use Swoft\Bean\Annotation\Mapping\Inject;
use Swoft\Http\Message\ContentType;
use Swoft\Http\Message\Response;
use Swoft\Http\Server\Annotation\Mapping\Controller;
use Swoft\Http\Server\Annotation\Mapping\RequestMapping;
use Swoft\View\Renderer;
use Throwable;
use Swoft\Redis\Redis;

/**
 * Class HomeController
 * @Controller()
 */
class HomeController
{
    /**
     * @Inject("cache")
     * @var CacheInterface
     */
    private $cache;

    public function test()
    {
        $rand = uniqid();
        $key = "test";
        $this->cache->set($key, $rand, 3600 * 30);
        assert($rand === $this->cache->get($key));

    }
}