Skip to content

Instantly share code, notes, and snippets.

@Geolim4
Created November 20, 2017 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Geolim4/1fd919db4411db76e016f42c596c69e3 to your computer and use it in GitHub Desktop.
Save Geolim4/1fd919db4411db76e016f42c596c69e3 to your computer and use it in GitHub Desktop.
Index: Service/Cache.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- Service/Cache.php (revision e972969478c2ad67d9befe771b5783d57aea7542)
+++ Service/Cache.php (revision )
@@ -26,10 +26,15 @@
*/
class Cache
{
+ /**
+ * @var self
+ */
+ protected static $selfInstance;
+
/**
* @var array
*/
- private $config = [];
+ protected $config = [];
/**
* @var Stopwatch
@@ -41,7 +46,7 @@
*
* @var \phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface[]
*/
- private $cacheInstances = [];
+ protected $cacheInstances = [];
/**
* Cache constructor.
@@ -51,12 +56,26 @@
*
* @throws \phpFastCache\Exceptions\phpFastCacheDriverException
*/
- public function __construct($config, Stopwatch $stopwatch = null)
+ protected function __construct($config, Stopwatch $stopwatch = null)
{
$this->config = (array) $config;
$this->stopwatch = $stopwatch;
}
+ /**
+ * Factory instance provider
+ *
+ * @param array $config
+ * @param Stopwatch $stopwatch
+ *
+ * @throws \phpFastCache\Exceptions\phpFastCacheDriverException
+ * @return self
+ */
+ public static function getInstance($config, Stopwatch $stopwatch = null)
+ {
+ return self::$selfInstance ?: self::$selfInstance = new self($config, $stopwatch);
+ }
+
/**
* Set a new cache instance
*
Index: Resources/config/services.yml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- Resources/config/services.yml (revision e972969478c2ad67d9befe771b5783d57aea7542)
+++ Resources/config/services.yml (revision )
@@ -7,6 +7,7 @@
services:
phpfastcache:
+ factory: ['%php_fast_cache.cache.class%', 'getInstance']
class: "%php_fast_cache.cache.class%"
arguments:
- "%phpfastcache%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment