mirror of
https://github.com/silverstripe/silverstripe-versionfeed
synced 2024-10-22 09:05:31 +00:00
parent
d6fca1a5c4
commit
7f3adbf4d8
@ -7,11 +7,20 @@ namespace VersionFeed\Filters;
|
|||||||
*/
|
*/
|
||||||
class CachedContentFilter extends ContentFilter {
|
class CachedContentFilter extends ContentFilter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable caching
|
||||||
|
*
|
||||||
|
* @config
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
private static $cache_enabled = true;
|
||||||
|
|
||||||
public function getContent($key, $callback) {
|
public function getContent($key, $callback) {
|
||||||
$cache = $this->getCache();
|
$cache = $this->getCache();
|
||||||
|
|
||||||
// Return cached value if available
|
// Return cached value if available
|
||||||
$result = isset($_GET['flush'])
|
$cacheEnabled = \Config::inst()->get(get_class(), 'cache_enabled');
|
||||||
|
$result = (isset($_GET['flush']) || !$cacheEnabled)
|
||||||
? null
|
? null
|
||||||
: $cache->load($key);
|
: $cache->load($key);
|
||||||
if($result) return $result;
|
if($result) return $result;
|
||||||
|
@ -17,7 +17,9 @@ class VersionFeedFunctionalTest extends FunctionalTest {
|
|||||||
$this->userIP = isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : null;
|
$this->userIP = isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : null;
|
||||||
|
|
||||||
Config::nest();
|
Config::nest();
|
||||||
Config::inst()->update('VersionFeed\Filters\RateLimitFilter', 'lock_timeout', 20);
|
// Disable caching and locking by default
|
||||||
|
Config::inst()->update('VersionFeed\Filters\CachedContentFilter', 'cache_enabled', false);
|
||||||
|
Config::inst()->update('VersionFeed\Filters\RateLimitFilter', 'lock_timeout', 0);
|
||||||
Config::inst()->update('VersionFeed\Filters\RateLimitFilter', 'lock_bypage', false);
|
Config::inst()->update('VersionFeed\Filters\RateLimitFilter', 'lock_bypage', false);
|
||||||
Config::inst()->update('VersionFeed\Filters\RateLimitFilter', 'lock_byuserip', false);
|
Config::inst()->update('VersionFeed\Filters\RateLimitFilter', 'lock_byuserip', false);
|
||||||
Config::inst()->update('VersionFeed\Filters\RateLimitFilter', 'lock_cooldown', false);
|
Config::inst()->update('VersionFeed\Filters\RateLimitFilter', 'lock_cooldown', false);
|
||||||
@ -56,6 +58,9 @@ class VersionFeedFunctionalTest extends FunctionalTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testRateLimiting() {
|
public function testRateLimiting() {
|
||||||
|
// Re-enable locking just for this test
|
||||||
|
Config::inst()->update('VersionFeed\Filters\RateLimitFilter', 'lock_timeout', 20);
|
||||||
|
Config::inst()->update('VersionFeed\Filters\CachedContentFilter', 'cache_enabled', true);
|
||||||
|
|
||||||
$page1 = $this->createPageWithChanges(array('PublicHistory' => true, 'Title' => 'Page1'));
|
$page1 = $this->createPageWithChanges(array('PublicHistory' => true, 'Title' => 'Page1'));
|
||||||
$page2 = $this->createPageWithChanges(array('PublicHistory' => true, 'Title' => 'Page2'));
|
$page2 = $this->createPageWithChanges(array('PublicHistory' => true, 'Title' => 'Page2'));
|
||||||
@ -106,6 +111,8 @@ class VersionFeedFunctionalTest extends FunctionalTest {
|
|||||||
|
|
||||||
// Restore setting
|
// Restore setting
|
||||||
Config::inst()->update('VersionFeed\Filters\RateLimitFilter', 'lock_byuserip', false);
|
Config::inst()->update('VersionFeed\Filters\RateLimitFilter', 'lock_byuserip', false);
|
||||||
|
Config::inst()->update('VersionFeed\Filters\RateLimitFilter', 'lock_timeout', 0);
|
||||||
|
Config::inst()->update('VersionFeed\Filters\CachedContentFilter', 'cache_enabled', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testContainsChangesForPageOnly() {
|
public function testContainsChangesForPageOnly() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user