2015-05-20 15:28:50 4984次浏览 3条回答 0 悬赏 0 金钱

好困惑啊! 缓存到底应该怎么用? 既保证数据的实时性、又能减轻数据库的压力,看似简单的缓存,其实深奥无比,求大神们出招支援下!

  • 回答于 2015-05-20 16:00 举报

    为了保证数据的实时性,可以做缓存依赖。

    1 条回复
    回复于 2015-05-20 16:04 回复

    舰长,能稍微描述一下 缓存依赖吗?

  • 回答于 2015-05-20 16:03 举报

    这个可以列个专题讨论

    1 条回复
    回复于 2015-05-20 16:05 回复

    这个可以有。。。。。。。

  • 回答于 2015-05-20 16:09 举报

    缓存依赖 $dependency

    
        /**
         * Stores a value identified by a key into cache.
         * If the cache already contains such a key, the existing value and
         * expiration time will be replaced with the new ones, respectively.
         *
         * @param mixed $key a key identifying the value to be cached. This can be a simple string or
         * a complex data structure consisting of factors representing the key.
         * @param mixed $value the value to be cached
         * @param integer $duration the number of seconds in which the cached value will expire. 0 means never expire.
         * @param Dependency $dependency dependency of the cached item. If the dependency changes,
         * the corresponding value in the cache will be invalidated when it is fetched via [[get()]].
         * This parameter is ignored if [[serializer]] is false.
         * @return boolean whether the value is successfully stored into cache
         */
        public function set($key, $value, $duration = 0, $dependency = null)
        {
            if ($dependency !== null && $this->serializer !== false) {
                $dependency->evaluateDependency($this);
            }
            if ($this->serializer === null) {
                $value = serialize([$value, $dependency]);
            } elseif ($this->serializer !== false) {
                $value = call_user_func($this->serializer[0], [$value, $dependency]);
            }
            $key = $this->buildKey($key);
    
            return $this->setValue($key, $value, $duration);
        }
    
    2 条回复
    回复于 2015-05-20 22:44 回复

    这个是缓存依赖? 这个是设置缓存吧?

    回复于 2015-05-21 10:35 回复

    这个缓存的时候,可以针对这个缓存做依赖,换句话说,就是你依赖的其他缓存变动,这个缓存就会失效

    觉得很赞
您需要登录后才可以回答。登录 | 立即注册
word1018808441
CEO

word1018808441 重庆

注册时间:2015-03-24
最后登录:2018-07-04
在线时长:629小时49分
  • 粉丝49
  • 金钱7395
  • 威望40
  • 积分14085

热门问题