ExportCache.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\common\cache;
  15. class ExportCache extends BaseCache
  16. {
  17. protected $uniqid = '';
  18. public function __construct()
  19. {
  20. parent::__construct();
  21. //以微秒计的当前时间,生成一个唯一的 ID,以tagname为前缀
  22. $this->uniqid = md5(uniqid($this->tagName,true).mt_rand());
  23. }
  24. /**
  25. * @notes 获取excel缓存目录
  26. * @return string
  27. * @author 令狐冲
  28. * @date 2021/7/28 17:36
  29. */
  30. public function getSrc()
  31. {
  32. return app()->getRootPath() . 'runtime/file/export/'.date('Y-m').'/'.$this->uniqid.'/';
  33. }
  34. /**
  35. * @notes 设置文件路径缓存地址
  36. * @param $fileName
  37. * @return string
  38. * @author 令狐冲
  39. * @date 2021/7/28 17:36
  40. */
  41. public function setFile($fileName)
  42. {
  43. $src = $this->getSrc();
  44. $key = md5($src . $fileName) . time();
  45. $this->set($key, ['src' => $src, 'name' => $fileName], 300);
  46. return $key;
  47. }
  48. /**
  49. * @notes 获取文件缓存的路径
  50. * @param $key
  51. * @return mixed
  52. * @author 令狐冲
  53. * @date 2021/7/26 18:36
  54. */
  55. public function getFile($key)
  56. {
  57. return $this->get($key);
  58. }
  59. }