vendor/codeages/biz-framework/src/Dao/CacheStrategy/RowStrategy.php

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php

namespace Codeages\Biz\Framework\Dao\CacheStrategy;

use Codeages\Biz\Framework\Dao\Annotation\MetadataReader;
use Codeages\Biz\Framework\Dao\CacheStrategy;
use Codeages\Biz\Framework\Dao\GeneralDaoInterface;

/**
 * 行级别缓存策略
 */
class RowStrategy implements CacheStrategy
{
    /**
     * @var \Redis
     */
    private $redis;

    /**
     * @var MetadataReader
     */
    private $metadataReader;

    const LIFE_TIME = 3600;

    public function __construct($redis, MetadataReader $metadataReader)
    {
        $this->redis = $redis;
        $this->metadataReader = $metadataReader;
    }

    public function beforeQuery(GeneralDaoInterface $dao, $method, $arguments)
    {
        if (0 !== strpos($method, 'get')) {
            return false;
        }

        $metadata = $this->metadataReader->read($dao);

        $key = $this->getCacheKey($dao, $metadata, $method, $arguments);
        if (!$key) {
            return false;
        }

        $cache = $this->redis->get($key);
        if (false === $cache) {
            return false;
        }

        if ('get' === $method) {
            return $cache;
        }

        return $this->redis->get($cache);
    }

    public function afterQuery(GeneralDaoInterface $dao, $method, $arguments, $data)
    {
        if (empty($data)) {
            return;

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。