PageCache.Class.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * 小程序商品首页数据cache
  4. * Created by PhpStorm.
  5. * User: kang
  6. * Date: 2021/7/12
  7. * Time: 18:15
  8. */
  9. namespace JinDouYun\Cache;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\ResultWrapper;
  12. use Mall\Framework\Factory;
  13. class PageCache
  14. {
  15. private $cache;
  16. private $enterpriseId;
  17. private $userCenterId;
  18. private $cacheKey = 'Page';
  19. public function __construct($enterpriseId = false, $userCenterId = false)
  20. {
  21. $this->enterpriseId = $enterpriseId;
  22. $this->userCenterId = $userCenterId;
  23. $this->cache = Factory::cache('default');
  24. }
  25. /**---------------------------------------------小程序首页------------------------------------------------**/
  26. /**
  27. * 添加
  28. * @param $md5Key
  29. * @param $pageData
  30. * @return bool
  31. */
  32. public function addPage($md5Key, $pageData)
  33. {
  34. $data = json_encode($pageData);
  35. $result = $this->cache->hset($this->cacheKey, $md5Key, $data);
  36. if(!$result){
  37. return false;
  38. }
  39. return true;
  40. }
  41. /**
  42. * 查询
  43. * @param $md5Key
  44. * @return array
  45. */
  46. public function getPage($md5Key)
  47. {
  48. $result = $this->cache->hget($this->cacheKey, $md5Key);
  49. if (!$result) return [];
  50. $returnData = json_decode($result, true);
  51. return $returnData;
  52. }
  53. /**
  54. * 删除
  55. * @param $paegId
  56. */
  57. public function delPage($paegId = false)
  58. {
  59. if($paegId){
  60. $this->cache->hdel($this->cacheKey, $paegId);
  61. }else{
  62. $this->cache->del($this->cacheKey);
  63. }
  64. }
  65. }