CCache.php 930 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * FecShop file.
  4. *
  5. * @link http://www.fecshop.com/
  6. * @copyright Copyright (c) 2016 FecShop Software LLC
  7. * @license http://www.fecshop.com/license/
  8. */
  9. namespace fec\helpers;
  10. use Yii;
  11. /**
  12. * @author Terry Zhao <2358269014@qq.com>
  13. * @since 1.0
  14. */
  15. class CCache{
  16. const ALL_ROLE_KEY_CACHE_HANDLE = 'all_role_key_cache'; # 菜单role cache
  17. # 得到cache 组件。
  18. public static function cacheM(){
  19. return Yii::$app->cache;
  20. }
  21. # 1.得到 cache
  22. public static function get($handle){
  23. $cache = self::cacheM();
  24. return $cache->get($handle);
  25. }
  26. # 2.设置 cache
  27. public static function set($handle,$data,$timeout=0){
  28. $cache = self::cacheM();
  29. if($timeout)
  30. return $cache->set($handle,$data,$timeout);
  31. return $cache->set($handle,$data);
  32. }
  33. # 3.刷新 Cache
  34. public static function flushAll(){
  35. $cache = self::cacheM();
  36. $cache->flush();
  37. }
  38. }