<?php
namespace Qii\Driver;

use Qii\Autoloader\Import;
use Qii\Autoloader\Psr4;

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

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

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

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