PHP code example of goldfinch / silverstripe-dynamiccache
1. Go to this page and download the library: Download goldfinch/silverstripe-dynamiccache library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
goldfinch / silverstripe-dynamiccache example snippets
DynamicCache::inst()->clear();
class CacheCustomisation extends DynamicCacheExtension {
public function updateEnabled(&$enabled) {
// Disable caching for this request if a user is logged in
if (Member::currentUserID()) $enabled = false;
// Disable caching for this request if in dev mode
elseif (Director::isDev()) $enabled = false;
// Disable caching for this request if we have a message to display
// or the request shouldn't be cached for other reasons
elseif (Session::get('StatusMessage') || Session::get('Uncachable')) $enabled = false;
}
public function updateCacheKeyFragments(array &$fragments) {
// For any url segment cache between mobile and desktop devices.
$fragments[] = MobileBrowserDetector::is_mobile() ? 'mobile' : 'desktop';
}
}