| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496 |
- <?php
- /**
- * Created by PhpStorm.
- * User: dingran
- * Date: 2018/6/5
- * Time: 上午9:34
- */
- namespace app\common\helpers;
- use Illuminate\Support\Str;
- class Cache
- {
- public static $i = null;
- public static function setUniacid($uniacid = 0)
- {
- self::$i = $uniacid ?: \YunShop::app()->uniacid;
- }
- public static function getUniacid()
- {
- if (is_null(self::$i)) {
- self::setUniacid();
- }
- return self::$i;
- }
- /**
- * Get a cache store instance by name.
- *
- * @param string|null $name
- * @return mixed
- * @static
- */
- public static function store($name = null)
- {
- return \Cache::store($name);
- }
- /**
- * Get a cache driver instance.
- *
- * @param string $driver
- * @return mixed
- * @static
- */
- public static function driver($driver = null)
- {
- return \Cache::driver($driver);
- }
- /**
- * Create a new cache repository with the given implementation.
- *
- * @param \Illuminate\Contracts\Cache\Store $store
- * @return \Illuminate\Cache\Repository
- * @static
- */
- public static function repository($store)
- {
- return \Cache::repository($store);
- }
- /**
- * Get the default cache driver name.
- *
- * @return string
- * @static
- */
- public static function getDefaultDriver()
- {
- return \Cache::getDefaultDriver();
- }
- /**
- * Set the default cache driver name.
- *
- * @param string $name
- * @return void
- * @static
- */
- public static function setDefaultDriver($name)
- {
- \Cache::setDefaultDriver($name);
- }
- /**
- * Register a custom driver creator Closure.
- *
- * @param string $driver
- * @param \Closure $callback
- * @return $this
- * @static
- */
- public static function extend($driver, $callback)
- {
- return \Cache::extend($driver, $callback);
- }
- /**
- * Set the event dispatcher instance.
- *
- * @param \Illuminate\Contracts\Events\Dispatcher $events
- * @return void
- * @static
- */
- public static function setEventDispatcher($events)
- {
- \Cache::setEventDispatcher($events);
- }
- /**
- * Determine if an item exists in the cache.
- *
- * @param string $key
- * @return bool
- * @static
- */
- public static function has($key)
- {
- return \Cache::has(self::getUniacid() . $key);
- }
- /**
- * Retrieve an item from the cache by key.
- *
- * @param string $key
- * @param mixed $default
- * @return mixed
- * @static
- */
- public static function get($key, $default = null , $tags = [])
- {
- if (!$tags){
- return \Cache::get(self::getUniacid() . $key, $default);
- }else{
- return \Cache::tags($tags)->get(self::getUniacid() . $key, $default);
- }
- }
- /**
- * Retrieve multiple items from the cache by key.
- *
- * Items not found in the cache will have a null value.
- *
- * @param array $keys
- * @return array
- * @static
- */
- public static function many($keys)
- {
- return \Cache::many(self::getUniacid() . $keys);
- }
- /**
- * Retrieve an item from the cache and delete it.
- *
- * @param string $key
- * @param mixed $default
- * @return mixed
- * @static
- */
- public static function pull($key, $default = null)
- {
- return \Cache::pull(self::getUniacid() . $key, $default);
- }
- /**
- * Store an item in the cache.
- *
- * @param string $key
- * @param mixed $value
- * @param \DateTime|float|int $minutes
- * @return void
- * @static
- */
- public static function put($key, $value, $minutes = null,$tags = [])
- {
- if ($minutes) {
- $minutes = $minutes * 60;
- }
- if (!$tags){
- \Cache::put(self::getUniacid() . $key, $value, $minutes);
- } elseif (is_array($tags)){
- \Cache::tags($tags)->put(self::getUniacid() . $key, $value, $minutes);
- }
- }
- /**
- * Store multiple items in the cache for a given number of minutes.
- *
- * @param array $values
- * @param float|int $minutes
- * @return void
- * @static
- */
- public static function putMany($values, $minutes)
- {
- \Cache::putMany($values, $minutes);
- }
- /**
- * Store an item in the cache if the key does not exist.
- *
- * @param string $key
- * @param mixed $value
- * @param \DateTime|float|int $minutes
- * @return bool
- * @static
- */
- public static function add($key, $value, $minutes)
- {
- return \Cache::add(self::getUniacid() . $key, $value, $minutes);
- }
- /**
- * Increment the value of an item in the cache.
- *
- * @param string $key
- * @param mixed $value
- * @return int|bool
- * @static
- */
- public static function increment($key, $value = 1)
- {
- return \Cache::increment(self::getUniacid() . $key, $value);
- }
- /**
- * Decrement the value of an item in the cache.
- *
- * @param string $key
- * @param mixed $value
- * @return int|bool
- * @static
- */
- public static function decrement($key, $value = 1)
- {
- return \Cache::decrement(self::getUniacid() . $key, $value);
- }
- /**
- * Store an item in the cache indefinitely.
- *
- * @param string $key
- * @param mixed $value
- * @return void
- * @static
- */
- public static function forever($key, $value)
- {
- \Cache::forever(self::getUniacid() . $key, $value);
- }
- /**
- * Get an item from the cache, or store the default value.
- *
- * @param string $key
- * @param \DateTime|float|int $seconds
- * @param \Closure $callback
- * @return mixed
- * @static
- */
- public static function remember($key, $minutes, $callback)
- {
- return \Cache::remember(self::getUniacid() . $key, $minutes, $callback);
- }
- /**
- * Get an item from the cache, or store the default value forever.
- *
- * @param string $key
- * @param \Closure $callback
- * @return mixed
- * @static
- */
- public static function sear($key, $callback)
- {
- return \Cache::sear(self::getUniacid() . $key, $callback);
- }
- /**
- * Get an item from the cache, or store the default value forever.
- *
- * @param string $key
- * @param \Closure $callback
- * @return mixed
- * @static
- */
- public static function rememberForever($key, $callback)
- {
- return \Cache::rememberForever(self::getUniacid() . $key, $callback);
- }
- /**
- * Remove an item from the cache.
- *
- * @param string $key
- * @return bool
- * @static
- */
- public static function forget($key)
- {
- return \Cache::forget(self::getUniacid() . $key);
- }
- /**
- * Begin executing a new tags operation if the store supports it.
- *
- * @param array|mixed $names
- * @return \Illuminate\Cache\TaggedCache
- * @throws \BadMethodCallException
- * @static
- */
- public static function tags($names)
- {
- return \Cache::tags($names);
- }
- /**
- * Get the default cache time.
- *
- * @return float|int
- * @static
- */
- public static function getDefaultCacheTime()
- {
- return \Cache::getDefaultCacheTime();
- }
- /**
- * Set the default cache time in minutes.
- *
- * @param float|int $minutes
- * @return void
- * @static
- */
- public static function setDefaultCacheTime($minutes)
- {
- \Cache::setDefaultCacheTime($minutes);
- }
- /**
- * Get the cache store implementation.
- *
- * @return \Illuminate\Contracts\Cache\Store
- * @static
- */
- public static function getStore()
- {
- return \Cache::getStore();
- }
- /**
- * Determine if a cached value exists.
- *
- * @param string $key
- * @return bool
- * @static
- */
- public static function offsetExists($key)
- {
- return \Cache::offsetExists(self::getUniacid() . $key);
- }
- /**
- * Retrieve an item from the cache by key.
- *
- * @param string $key
- * @return mixed
- * @static
- */
- public static function offsetGet($key)
- {
- return \Cache::offsetGet(self::getUniacid() . $key);
- }
- /**
- * Store an item in the cache for the default time.
- *
- * @param string $key
- * @param mixed $value
- * @return void
- * @static
- */
- public static function offsetSet($key, $value)
- {
- \Cache::offsetSet(self::getUniacid() . $key, $value);
- }
- /**
- * Remove an item from the cache.
- *
- * @param string $key
- * @return void
- * @static
- */
- public static function offsetUnset($key)
- {
- \Cache::offsetUnset(self::getUniacid() . $key);
- }
- /**
- * Register a custom macro.
- *
- * @param string $name
- * @param callable $macro
- * @return void
- * @static
- */
- public static function macro($name, $macro)
- {
- \Cache::macro($name, $macro);
- }
- /**
- * Checks if macro is registered.
- *
- * @param string $name
- * @return bool
- * @static
- */
- public static function hasMacro($name)
- {
- return \Cache::hasMacro($name);
- }
- /**
- * Dynamically handle calls to the class.
- *
- * @param string $method
- * @param array $parameters
- * @return mixed
- * @throws \BadMethodCallException
- * @static
- */
- public static function macroCall($method, $parameters)
- {
- return \Cache::macroCall($method, $parameters);
- }
- /**
- * Remove all items from the cache.
- *
- * @return void
- * @static
- */
- public static function flush($tags = [])
- {
- if(!$tags){
- \Cache::flush();
- }else{
- \Cache::tags($tags)->flush();
- }
- }
- /**
- * Get the Filesystem instance.
- *
- * @return \Illuminate\Filesystem\Filesystem
- * @static
- */
- public static function getFilesystem()
- {
- return \Cache::getFilesystem();
- }
- /**
- * Get the working directory of the cache.
- *
- * @return string
- * @static
- */
- public static function getDirectory()
- {
- return \Cache::getDirectory();
- }
- /**
- * Get the cache key prefix.
- *
- * @return string
- * @static
- */
- public static function getPrefix()
- {
- return \Cache::getPrefix();
- }
- }
|