PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.9.14
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.9.14
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / includes / Services / Cache.php

Cache.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.9.14, at includes/Services/Cache.php

58 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Cache Helper class
4 *
5 * @package WCPOS\WooCommercePOS
6 */
7
8 namespace WCPOS\WooCommercePOS\Services;
9
10 use WCPOS\Vendor\Phpfastcache\Drivers\Files\Config;
11 use WCPOS\Vendor\Phpfastcache\Drivers\Files\Driver;
12 use WCPOS\Vendor\Phpfastcache\EventManager;
13 use WCPOS\Vendor\Phpfastcache\Helper\Psr16Adapter;
14
15 /**
16 * Cache class.
17 */
18 class Cache {
19 /**
20 * Get the cache instance
21 *
22 * @param string $instance_id Instance ID.
23 *
24 * @return Psr16Adapter|object
25 */
26 public static function get_cache_instance( string $instance_id = 'default' ) {
27 static $cache = null;
28
29 if ( null === $cache ) {
30 $upload_dir = wp_upload_dir();
31 $cache_dir = $upload_dir['basedir'] . '/woocommerce_pos_cache';
32
33 if ( ! file_exists( $cache_dir ) ) {
34 wp_mkdir_p( $cache_dir );
35 }
36
37 // @phpstan-ignore-next-line.
38 $config = new Config(
39 array(
40 'path' => $cache_dir,
41 )
42 );
43
44 $event_manager = EventManager::getInstance();
45
46 // Generate a unique instance ID for each logged-in user.
47 // @phpstan-ignore-next-line.
48 $driver = new Driver( $config, $instance_id );
49 $driver->setEventManager( $event_manager );
50
51 // @phpstan-ignore-next-line.
52 $cache = new Psr16Adapter( $driver );
53 }
54
55 return $cache;
56 }
57 }
58