From 6bae804744f4fb513ffc79c116ce6cee561ce6e7 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Wed, 22 Feb 2017 14:34:07 +1300 Subject: [PATCH] API Use symfony/cache See https://github.com/silverstripe/silverstripe-framework/issues/6252 --- _config/cache.yml | 9 +++++++++ code/Controllers/CMSMain.php | 11 +++++------ tests/controller/CMSMainTest.php | 7 ++++--- 3 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 _config/cache.yml diff --git a/_config/cache.yml b/_config/cache.yml new file mode 100644 index 00000000..dfa6d70d --- /dev/null +++ b/_config/cache.yml @@ -0,0 +1,9 @@ +--- +After: + - '#corecache' +--- +SilverStripe\Core\Injector\Injector: + Psr\SimpleCache\CacheInterface.CMSMain_SiteTreeHints: + factory: SilverStripe\Core\Cache\CacheFactory + constructor: + namespace: "CMSMain_SiteTreeHints" diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index 4022ff31..fd8427eb 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -21,7 +21,7 @@ use SilverStripe\Control\HTTPResponse; use SilverStripe\Control\HTTPResponse_Exception; use SilverStripe\Core\Convert; use SilverStripe\Core\Injector\Injector; -use SilverStripe\Core\Cache; +use Psr\SimpleCache\CacheInterface; use SilverStripe\Forms\DateField; use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\FieldGroup; @@ -59,7 +59,6 @@ use SilverStripe\Security\SecurityToken; use SilverStripe\View\ArrayData; use SilverStripe\View\Requirements; use Translatable; -use Zend_Cache; use InvalidArgumentException; /** @@ -556,12 +555,12 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr } // Generate basic cache key. Too complex to encompass all variations - $cache = Cache::factory('CMSMain_SiteTreeHints'); + $cache = Injector::inst()->get(CacheInterface::class . '.CMSMain_SiteTreeHints'); $cacheKey = md5(implode('_', array(Member::currentUserID(), implode(',', $cacheCanCreate), implode(',', $classes)))); if ($this->getRequest()->getVar('flush')) { - $cache->clean(Zend_Cache::CLEANING_MODE_ALL); + $cache->clear(); } - $json = $cache->load($cacheKey); + $json = $cache->get($cacheKey); if (!$json) { $def['Root'] = array(); $def['Root']['disallowedChildren'] = array(); @@ -608,7 +607,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr $this->extend('updateSiteTreeHints', $def); $json = Convert::raw2json($def); - $cache->save($json, $cacheKey); + $cache->set($cacheKey, $json); } return $json; } diff --git a/tests/controller/CMSMainTest.php b/tests/controller/CMSMainTest.php index 3ac91a7b..946ca72b 100644 --- a/tests/controller/CMSMainTest.php +++ b/tests/controller/CMSMainTest.php @@ -1,5 +1,6 @@ get(CacheInterface::class . '.CMSMain_SiteTreeHints'); // Login as user with root creation privileges $user = $this->objFromFixture('SilverStripe\\Security\\Member', 'rootedituser'); $user->logIn(); - $cache->clean(Zend_Cache::CLEANING_MODE_ALL); + $cache->clear(); $rawHints = singleton('SilverStripe\\CMS\\Controllers\\CMSMain')->SiteTreeHints(); $this->assertNotNull($rawHints);