-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCache.php
44 lines (35 loc) · 1.03 KB
/
Cache.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local;
use MatthiasMullie\Scrapbook\Adapters\Flysystem;
use MatthiasMullie\Scrapbook\Psr6\Pool;
class OWMPCache {
// Hold the class instance.
private static $instance;
// Hold the PSR6 cache.
private Pool $pool;
private function getFsCache(string $pathToCache) {
$adapter = new Local($pathToCache, LOCK_EX);
$filesystem = new Filesystem($adapter);
// create Scrapbook KeyValueStore object
$cache = new Flysystem($filesystem);
return $cache;
}
// The constructor is private
// to prevent initiation with outer code.
private function __construct($pathToCache)
{
$fsCache = $this->getFsCache($pathToCache);
$this->pool = new Pool($fsCache);
}
// The object is created from within the class itself
// only if the class has no instance.
public static function getInstance($pathToCache)
{
if (self::$instance == null)
{
self::$instance = new OWMPCache($pathToCache);
}
return self::$instance->pool;
}
}