<?php
namespace Qii\Driver\Traits;

trait Cache
{
    public $traitCache;
    /**
     * 设置Cache
     *
     * @param String $cache
     * @param Array $policy
     */
    final public function setCache($cache, $policy)
    {
        $this->traitCache = \Qii::getInstance()->setCache($cache, $policy);
        return $this->traitCache;
    }

    /**
     * 缓存内容
     *
     * @param String $id
     * @param Array $value
     * @param array $policy ['life_time' => 过期时间]
     * @return Bool
     */
    final public function cache($id, $value, $policy = array())
    {
        return $this->traitCache->set($id, $value, $policy);
    }

    /**
     * 获取缓存的类
     */
    final public function getCache()
    {
        return $this->traitCache;
    }

    /**
     * 获取缓存内容
     *
     * @param String $id
     * @return Array
     */
    final public function getCacheData($id)
    {
        return $this->traitCache->get($id);
    }
}