PHP code example of alan / swoft-cache-proxy

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

    

alan / swoft-cache-proxy example snippets


   'redis'               => [
       'class'         => RedisDb::class,
       'host'          => env("REDIS_HOST"),
       'port'          => env("REDIS_PORT"),
       'database'      => env("REDIS_DATABASE"),
       'retryInterval' => 10,
       'readTimeout'   => 0,
       'timeout'       => 2,
       'password'      => env("REDIS_PASSWORD"),
       'driver'        => 'phpredis',
       'option'        => [
           'prefix' => 'swoft_app_name',
           'serializer' => Redis::SERIALIZER_NONE,
       ],
   ],
   'redis.pool'          => [
       'class'       => \Swoft\Redis\Pool::class,
       'redisDb'     => \bean('redis'),
       'minActive'   => 10,
       'maxActive'   => 20,
       'maxWait'     => 0,
       'maxWaitTime' => 0,
       'maxIdleTime' => 60,
   ]
   

   use alan\swoft_cache_proxy\Annotation\Mapping\Cache;
   use  alan\swoft_cache_proxy\Helper\CacheRspHelper;
   
   /**
    * @Cache(isQuery=true)
    * @return array
    */
   public function testQuery() {
       $cacheFlagValue = 123;
       $now = time(); //业务代码
       return CacheRspHelper::makeRsp(['now' => $now], $cacheFlagValue);
   }
   
   /**
    * @Cache(isQuery=false)
    * @return array
    */
   public function testUpdate() {
       //... 业务上的更新操作
       $data = []; //业务操作返回
       return CacheRspHelper::makeRsp($data, $cacheFlagValue);
   }