The specific statement is that variable information can be cached.
Settings: yii: APP ()-> cache-> set (name, value, expiration time );
Use: yii: APP ()-> cache-> get (name );
Delete: yii: APP ()-> cache-> Delete (name );
Clear: yii: APP ()-> cache-> flush ();
Application of cached data:
Used to cache data: You can customize a method in the data model to obtain the desired data and then cache it.
For example, when obtaining product details, you can customize a method to obtain product details in the Goods Model:
/** Get product details * @ $ ID: Product ID */function getgoodsinfobypk ($ id) {If (yii: APP () -> cache-> get ('goodsinfo '. $ id) {// If cache data exists, the cached data is returned. If no cache data exists, the data is retrieved from the database and saved to the cache. $ goods_info = yii: APP () -> cache-> get ('goodsinfo '. $ id);} else {$ goods_info = $ this-> findbysql ($ id); yii: APP ()-> cache-> set ('goodsinfo '. $ id, 3600);} return $ goods_info ;}