Skip to content

Commit 3695473

Browse files
committed
增加 静态缓存类
1 parent fcd6b7a commit 3695473

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/Cache/StaticCache.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Webguosai\Cache;
4+
5+
/**
6+
* 静态缓存
7+
*/
8+
class StaticCache
9+
{
10+
protected static $cacheMaps = [];
11+
12+
/**
13+
*
14+
* @param mixed $id 标识
15+
* @param callable $callable 回调方法
16+
* @param string $prefix 缓存前缀
17+
* @return mixed
18+
*/
19+
public static function get($id, callable $callable, string $prefix)
20+
{
21+
if (!isset(self::$cacheMaps[$prefix . $id])) {
22+
self::$cacheMaps[$prefix . $id] = $callable();
23+
}
24+
25+
return self::$cacheMaps[$prefix . $id];
26+
}
27+
}

0 commit comments

Comments
 (0)