woocommerce-pos
/
vendor_prefixed
/
phpfastcache
/
phpfastcache
/
lib
/
Phpfastcache
/
Drivers
/
Apcu
/
Driver.php
Driver.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.9.16, at vendor_prefixed/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Apcu/Driver.php
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * |
| 5 | * This file is part of phpFastCache. |
| 6 | * |
| 7 | * @license MIT License (MIT) |
| 8 | * |
| 9 | * For full copyright and license information, please see the docs/CREDITS.txt file. |
| 10 | * |
| 11 | * @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> https://www.phpfastcache.com |
| 12 | * @author Georges.L (Geolim4) <contact@geolim4.com> |
| 13 | * |
| 14 | */ |
| 15 | declare (strict_types=1); |
| 16 | namespace WCPOS\Vendor\Phpfastcache\Drivers\Apcu; |
| 17 | |
| 18 | use DateTime; |
| 19 | use WCPOS\Vendor\Phpfastcache\Cluster\AggregatablePoolInterface; |
| 20 | use WCPOS\Vendor\Phpfastcache\Core\Pool\DriverBaseTrait; |
| 21 | use WCPOS\Vendor\Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; |
| 22 | use WCPOS\Vendor\Phpfastcache\Entities\DriverStatistic; |
| 23 | use WCPOS\Vendor\Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException; |
| 24 | use WCPOS\Vendor\Psr\Cache\CacheItemInterface; |
| 25 | /** |
| 26 | * Class Driver |
| 27 | * @package phpFastCache\Drivers |
| 28 | * @property Config $config Config object |
| 29 | * @method Config getConfig() Return the config object |
| 30 | */ |
| 31 | class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface |
| 32 | { |
| 33 | use DriverBaseTrait; |
| 34 | /** |
| 35 | * @return bool |
| 36 | */ |
| 37 | public function driverCheck() : bool |
| 38 | { |
| 39 | return \extension_loaded('apcu') && \ini_get('apc.enabled'); |
| 40 | } |
| 41 | /** |
| 42 | * @return DriverStatistic |
| 43 | */ |
| 44 | public function getStats() : DriverStatistic |
| 45 | { |
| 46 | $stats = (array) \apcu_cache_info(); |
| 47 | $date = (new DateTime())->setTimestamp($stats['start_time']); |
| 48 | return (new DriverStatistic())->setData(\implode(', ', \array_keys($this->itemInstances)))->setInfo(\sprintf("The APCU cache is up since %s, and have %d item(s) in cache.\n For more information see RawData.", $date->format(\DATE_RFC2822), $stats['num_entries']))->setRawData($stats)->setSize((int) $stats['mem_size']); |
| 49 | } |
| 50 | /** |
| 51 | * @return bool |
| 52 | */ |
| 53 | protected function driverConnect() : bool |
| 54 | { |
| 55 | return \true; |
| 56 | } |
| 57 | /** |
| 58 | * @param CacheItemInterface $item |
| 59 | * @return bool |
| 60 | * @throws PhpfastcacheInvalidArgumentException |
| 61 | */ |
| 62 | protected function driverWrite(CacheItemInterface $item) : bool |
| 63 | { |
| 64 | /** |
| 65 | * Check for Cross-Driver type confusion |
| 66 | */ |
| 67 | if ($item instanceof Item) { |
| 68 | return (bool) \apcu_store($item->getKey(), $this->driverPreWrap($item), $item->getTtl()); |
| 69 | } |
| 70 | throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
| 71 | } |
| 72 | /** |
| 73 | * @param CacheItemInterface $item |
| 74 | * @return null|array |
| 75 | */ |
| 76 | protected function driverRead(CacheItemInterface $item) |
| 77 | { |
| 78 | $data = \apcu_fetch($item->getKey(), $success); |
| 79 | if ($success === \false) { |
| 80 | return null; |
| 81 | } |
| 82 | return $data; |
| 83 | } |
| 84 | /** |
| 85 | * @param CacheItemInterface $item |
| 86 | * @return bool |
| 87 | * @throws PhpfastcacheInvalidArgumentException |
| 88 | */ |
| 89 | protected function driverDelete(CacheItemInterface $item) : bool |
| 90 | { |
| 91 | /** |
| 92 | * Check for Cross-Driver type confusion |
| 93 | */ |
| 94 | if ($item instanceof Item) { |
| 95 | return (bool) \apcu_delete($item->getKey()); |
| 96 | } |
| 97 | throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
| 98 | } |
| 99 | /******************** |
| 100 | * |
| 101 | * PSR-6 Extended Methods |
| 102 | * |
| 103 | *******************/ |
| 104 | /** |
| 105 | * @return bool |
| 106 | */ |
| 107 | protected function driverClear() : bool |
| 108 | { |
| 109 | return @\apcu_clear_cache(); |
| 110 | } |
| 111 | } |
| 112 |