1515
1616namespace phpFastCache \Bundle \Service ;
1717
18- use phpFastCache \Cache \ExtendedCacheItemPoolInterface ;
18+ use phpFastCache \Core \ Pool \ExtendedCacheItemPoolInterface ;
1919use phpFastCache \CacheManager ;
2020use phpFastCache \Exceptions \phpFastCacheDriverException ;
2121use Symfony \Component \Stopwatch \Stopwatch ;
2626 */
2727class Cache
2828{
29+ /**
30+ * @var self
31+ */
32+ protected static $ selfInstance ;
33+
2934 /**
3035 * @var array
3136 */
32- private $ config = [];
37+ protected $ config = [];
3338
3439 /**
3540 * @var Stopwatch
@@ -39,9 +44,9 @@ class Cache
3944 /**
4045 * Contains all cache instances
4146 *
42- * @var \phpFastCache\Cache \ExtendedCacheItemPoolInterface[]
47+ * @var \phpFastCache\Core\Pool \ExtendedCacheItemPoolInterface[]
4348 */
44- private $ cacheInstances = [];
49+ protected $ cacheInstances = [];
4550
4651 /**
4752 * Cache constructor.
@@ -51,12 +56,26 @@ class Cache
5156 *
5257 * @throws \phpFastCache\Exceptions\phpFastCacheDriverException
5358 */
54- public function __construct ($ config , Stopwatch $ stopwatch = null )
59+ protected function __construct ($ config , Stopwatch $ stopwatch = null )
5560 {
5661 $ this ->config = (array ) $ config ;
5762 $ this ->stopwatch = $ stopwatch ;
5863 }
5964
65+ /**
66+ * Factory instance provider
67+ *
68+ * @param array $config
69+ * @param Stopwatch $stopwatch
70+ *
71+ * @throws \phpFastCache\Exceptions\phpFastCacheDriverException
72+ * @return self
73+ */
74+ public static function getInstance ($ config , Stopwatch $ stopwatch = null )
75+ {
76+ return self ::$ selfInstance ?: self ::$ selfInstance = new self ($ config , $ stopwatch );
77+ }
78+
6079 /**
6180 * Set a new cache instance
6281 *
@@ -65,7 +84,7 @@ public function __construct($config, Stopwatch $stopwatch = null)
6584 *
6685 * @throws \phpFastCache\Exceptions\phpFastCacheDriverException
6786 */
68- public function createInstance ($ name , ExtendedCacheItemPoolInterface $ instance )
87+ public function createInstance ($ name , $ instance )
6988 {
7089 if (array_key_exists ($ name , $ this ->cacheInstances ) && $ this ->cacheInstances [ $ name ] instanceof ExtendedCacheItemPoolInterface) {
7190 throw new phpFastCacheDriverException ("Cache instance ' {$ name }' already exists " );
@@ -78,7 +97,7 @@ public function createInstance($name, ExtendedCacheItemPoolInterface $instance)
7897 *
7998 * @param string $name Name of configured driver
8099 *
81- * @return \phpFastCache\Cache \ExtendedCacheItemPoolInterface
100+ * @return \phpFastCache\Core\Pool \ExtendedCacheItemPoolInterface
82101 *
83102 * @throws \phpFastCache\Exceptions\phpFastCacheDriverException
84103 */
@@ -106,7 +125,7 @@ public function get($name)
106125 }
107126
108127 /**
109- * @return \phpFastCache\Cache \ExtendedCacheItemPoolInterface
128+ * @return \phpFastCache\Core\Pool \ExtendedCacheItemPoolInterface
110129 */
111130 public function getTwigCacheInstance ()
112131 {
@@ -126,7 +145,7 @@ public function getConfig()
126145 /**
127146 * Return all cache instances
128147 *
129- * @return \phpFastCache\Cache \ExtendedCacheItemPoolInterface[]
148+ * @return \phpFastCache\Core\Pool \ExtendedCacheItemPoolInterface[]
130149 */
131150 public function getInstances ()
132151 {
0 commit comments