Skip to content

Commit

Permalink
API Use symfony/cache
Browse files Browse the repository at this point in the history
  • Loading branch information
chillu committed Feb 23, 2017
1 parent dd5c050 commit 88ab885
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
11 changes: 5 additions & 6 deletions code/Controllers/CMSMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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;
Expand Down Expand Up @@ -59,7 +59,6 @@
use SilverStripe\View\ArrayData;
use SilverStripe\View\Requirements;
use Translatable;
use Zend_Cache;
use InvalidArgumentException;

/**
Expand Down Expand Up @@ -556,12 +555,12 @@ public function SiteTreeHints()
}

// 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();
Expand Down Expand Up @@ -608,7 +607,7 @@ public function SiteTreeHints()
$this->extend('updateSiteTreeHints', $def);

$json = Convert::raw2json($def);
$cache->save($json, $cacheKey);
$cache->set($cacheKey, $json);
}
return $json;
}
Expand Down
7 changes: 4 additions & 3 deletions tests/controller/CMSMainTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use SilverStripe\Core\Injector\Injector;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\ValidationException;
Expand All @@ -9,7 +10,7 @@
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Admin\CMSBatchActionHandler;
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\Core\Cache;
use Psr\SimpleCache\CacheInterface;
use SilverStripe\Core\Convert;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Dev\TestOnly;
Expand Down Expand Up @@ -45,11 +46,11 @@ public function setUp()

public function testSiteTreeHints()
{
$cache = Cache::factory('CMSMain_SiteTreeHints');
$cache = Injector::inst()->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);
Expand Down

0 comments on commit 88ab885

Please sign in to comment.