本文整理汇总了PHP中SS_Cache::set_cache_lifetime方法的典型用法代码示例。如果您正苦于以下问题:PHP SS_Cache::set_cache_lifetime方法的具体用法?PHP SS_Cache::set_cache_lifetime怎么用?PHP SS_Cache::set_cache_lifetime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SS_Cache
的用法示例。
在下文中一共展示了SS_Cache::set_cache_lifetime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCacheDefault
public function testCacheDefault()
{
SS_Cache::set_cache_lifetime('default', 1200);
$default = SS_Cache::get_cache_lifetime('default');
$this->assertEquals(1200, $default['lifetime']);
$cache = SS_Cache::factory('somethingnew');
$this->assertEquals(1200, $cache->getOption('lifetime'));
}
示例2: testCacheLifetime
function testCacheLifetime()
{
SS_Cache::set_cache_lifetime('test', 0.5, 20);
$cache = SS_Cache::factory('test');
$cache->save('Good', 'cachekey');
$this->assertEquals('Good', $cache->load('cachekey'));
sleep(1);
$this->assertFalse($cache->load('cachekey'));
}
示例3: getCachedData
/**
* Builds a cache of events if one doesn't exist, store the cache for 12 hours . The cache is cleared / reset
* when a new event is published .
*
* @return json load of events to display
*/
public function getCachedData()
{
$cache = SS_Cache::factory('calendar');
SS_Cache::set_cache_lifetime('calendar', 60 * 60 * 12);
if (!($result = unserialize($cache->load('events')))) {
$result = $this->getData();
$cache->save(serialize($result), 'events');
}
return $result;
}
示例4: parse
public static function parse($arguments, $content = null, $parser = null)
{
if (!array_key_exists('repo', $arguments) || empty($arguments['repo']) || strpos($arguments['repo'], '/') <= 0) {
return '<p><i>GitHub repository undefined</i></p>';
}
//Get Config
$config = Config::inst()->forClass('GitHubShortCode');
$obj = new ViewableData();
//Add the Respository Setting
$obj->Repository = $arguments['repo'];
//Add Layout
if (array_key_exists('layout', $arguments) && ($arguments['layout'] == 'inline' || $arguments['layout'] == 'stacked')) {
$obj->Layout = $arguments['layout'];
} else {
$obj->Layout = 'inline';
}
//Add the button config
if (array_key_exists('show', $arguments) && ($arguments['show'] == 'both' || $arguments['show'] == 'stars' || $arguments['show'] == 'forks')) {
$obj->ShowButton = $arguments['show'];
} else {
$obj->ShowButton = 'both';
}
//Retrieve Stats
SS_Cache::set_cache_lifetime('GitHubShortCode', $config->CacheTime);
$cacheKey = md5('GitHubShortCode_' . $arguments['repo']);
$cache = SS_Cache::factory('GitHubShortCode');
$cachedData = $cache->load($cacheKey);
if ($cachedData == null) {
$response = self::getFromAPI($arguments['repo'], $config);
//Verify a 200, if not say the repo errored out and cache false
if (empty($response) || $response === false || !property_exists($response, 'watchers') || !property_exists($response, 'forks')) {
$cachedData = array('stargazers' => 'N/A', 'forks' => 'N/A');
} else {
if ($config->UseShortHandNumbers == true) {
$stargazers = self::shortHandNumber($response->stargazers_count);
$forks = self::shortHandNumber($response->forks);
} else {
$stargazers = number_format($response->stargazers_count);
$forks = number_format($response->forks);
}
$cachedData = array('stargazers' => $stargazers, 'forks' => $forks);
}
//Cache response to file system
$cache->save(serialize($cachedData), $cacheKey);
} else {
$cachedData = unserialize($cachedData);
}
$obj->Stargazers = $cachedData['stargazers'];
$obj->Forks = $cachedData['forks'];
//Init ss viewer and render
Requirements::css(GITHUBSHORTCODE_BASE . '/css/GitHubButtons.css');
$ssViewer = new SSViewer('GitHubButtons');
return $ssViewer->process($obj);
}
开发者ID:helpfulrobot,项目名称:webbuilders-group-silverstripe-githubshortcode,代码行数:54,代码来源:GitHubShortCode.php
示例5: parse
public static function parse($arguments, $content = null, $parser = null)
{
if (!array_key_exists('package', $arguments) || empty($arguments['package']) || strpos($arguments['package'], '/') <= 0) {
return '<p><i>Packagist package undefined</i></p>';
}
//Get Config
$config = Config::inst()->forClass('PackagistShortCode');
$obj = new ViewableData();
//Add the Respository Setting
$obj->Package = $arguments['package'];
//Add the button config
if (array_key_exists('mode', $arguments) && ($arguments['mode'] == 'total' || $arguments['mode'] == 'monthly' || $arguments['mode'] == 'daily')) {
$obj->DisplayMode = $arguments['mode'];
} else {
$obj->DisplayMode = 'total';
}
//Retrieve Stats
SS_Cache::set_cache_lifetime('PackagistShortCode', $config->CacheTime);
$cacheKey = md5('packagistshortcode_' . $arguments['package']);
$cache = SS_Cache::factory('PackagistShortCode');
$cachedData = $cache->load($cacheKey);
if ($cachedData == null) {
$response = self::getFromAPI($arguments['package']);
//Verify a 200, if not say the repo errored out and cache false
if (empty($response) || $response === false || !property_exists($response, 'package')) {
$cachedData = array('total' => 'N/A', 'monthly' => 'N/A', 'daily' => 'N/A');
} else {
if ($config->UseShortHandNumbers == true) {
$totalDownloads = self::shortHandNumber($response->package->downloads->total);
$monthlyDownloads = self::shortHandNumber($response->package->downloads->monthly);
$dailyDownloads = self::shortHandNumber($response->package->downloads->daily);
} else {
$totalDownloads = number_format($response->package->downloads->total);
$monthlyDownloads = number_format($response->package->downloads->monthly);
$dailyDownloads = number_format($response->package->downloads->daily);
}
$cachedData = array('total' => $totalDownloads, 'monthly' => $monthlyDownloads, 'daily' => $dailyDownloads);
}
//Cache response to file system
$cache->save(serialize($cachedData), $cacheKey);
} else {
$cachedData = unserialize($cachedData);
}
$obj->TotalDownloads = $cachedData['total'];
$obj->MonthlyDownloads = $cachedData['monthly'];
$obj->DailyDownloads = $cachedData['daily'];
//Init ss viewer and render
Requirements::css(PACKAGISTSHORTCODE_BASE . '/css/PackagistButton.css');
$ssViewer = new SSViewer('PackagistButton');
return $ssViewer->process($obj);
}
开发者ID:helpfulrobot,项目名称:webbuilders-group-silverstripe-packagistshortcode,代码行数:51,代码来源:PackagistShortCode.php
示例6: getStructure
/**
* Sitetree getter, caches the whole sitetree per logged in user groups.
* If a $partialChild is defined then the cache is bypassed and a partial sitetree is returned.
*
* @param Int $id Optional id used to define the parent to kick off from.
* @param SiteTree $partialChild Optional partial child to get a site tree section from root.
*/
public function getStructure($id = 0, $partialChild = null)
{
if (!Member::currentUserID()) {
throw new Exception('SiteTreeOrigamiApi::getStructure Not logged in');
}
if ($partialChild) {
$stack = array_reverse($partialChild->parentStack());
$result = $this->_structure($id, $stack);
} else {
// Check the cache.
SS_Cache::set_cache_lifetime('SiteTree_Groups', 60 * 60);
//one hour
$cache = SS_Cache::factory('SiteTree_Groups', 'Output', array('automatic_serialization' => true));
// If there isn't a cached response call the API.
if (!($result = $cache->load(SiteTreeOrigamiApi::get_cache_key()))) {
$result = $this->_structure($id);
$cache->save($result, SiteTreeOrigamiApi::get_cache_key());
}
}
return $result;
}
示例7: IsProcessed
public function IsProcessed()
{
if ($this->VimeoProcessingStatus == 'finished') {
return true;
} else {
$cache = SS_Cache::factory('VimeoVideoFile_ApiRequest');
SS_Cache::set_cache_lifetime('VimeoVideoFile_ApiRequest', Config::inst()->get('VimeoVideoFile', 'api_request_time'));
// set the waiting time
if (!($result = $cache->load($this->ID))) {
switch ($this->VimeoProcessingStatus) {
case 'unprocessed':
$this->process();
break;
case 'updating':
case 'processing':
$this->appendLog($this->getLogFile(), 'IsProcessed - processing');
$lib = new \Vimeo\Vimeo(Config::inst()->get('VimeoVideoFile', 'client_id'), Config::inst()->get('VimeoVideoFile', 'client_secret'), Config::inst()->get('VimeoVideoFile', 'access_token'));
// Send a request to vimeo for uploading the new video
$video_data = $lib->request($this->VimeoURI);
$this->extractUrls($video_data);
// Set Title, Album and player preset
$lib->request($this->VimeoURI, array('name' => $this->Name), 'PATCH');
if (Config::inst()->get('VimeoVideoFile', 'album_id')) {
$res = $lib->request('/me/albums/' . Config::inst()->get('VimeoVideoFile', 'album_id') . $this->VimeoURI, array(), 'PUT');
$this->appendLog($this->getLogFile(), 'Updated Album', print_r($res, true));
}
if (Config::inst()->get('VimeoVideoFile', 'preset_id')) {
$res = $lib->request($this->VimeoURI . '/presets/' . Config::inst()->get('VimeoVideoFile', 'preset_id'), array(), 'PUT');
$this->appendLog($this->getLogFile(), 'Updated Player Preset', print_r($res, true));
}
break;
}
$result = $this->VimeoProcessingStatus;
$cache->save($result, $this->ID);
}
return $result == 'finished';
}
}
示例8:
<?php
// recommended update time is 20 mins so play safe and go with 30.
SS_Cache::set_cache_lifetime('any', 30 * 60);
示例9: SS_LogEmailWriter
<?php
/**
* SilverStripe Project
*/
global $project;
$project = 'mysite';
/**
* _ss_environment.php
*/
require_once "conf/ConfigureFromEnv.php";
/**
* Email errors
*/
if (!Director::isDev()) {
SS_Log::add_writer(new SS_LogEmailWriter(Email::getAdminEmail()), SS_Log::NOTICE, '<=');
}
/**
* Keep the cache clean
*/
if (isset($_REQUEST['flush'])) {
SS_Cache::set_cache_lifetime('any', -1, 100);
}
/**
* Locale
*/
i18n::set_locale('en_US');
示例10: getCachedCall
/**
* This returns API responses saved to a SS_Cache file instead of the API response directly
* as the Flickr API is often not reliable
*
* @param String $funcName Name of the function to call if cache expired or does not exist
* @param array $args Arguments for the function
* @return ArrayList<FlickrPhoto|FlickrPhotoset>
*/
public function getCachedCall($funcName, $args = array())
{
$result = null;
$argsCount = count($args);
if ($argsCount < 1) {
return $result;
}
// build up a unique cache name
$cacheKey = array($funcName);
foreach ($args as $arg) {
$cacheKey[] = $arg;
}
// to hide api key and remove non alphanumeric characters
$cacheKey = md5(implode('_', $cacheKey));
// setup cache
$cache = SS_Cache::factory('FlickrService');
$cache->setOption('automatic_serialization', true);
SS_Cache::set_cache_lifetime('FlickrService', $this->config()->flickr_hard_cache_expiry);
// check if cached response exists or soft expiry has elapsed
$metadata = $cache->getBackend()->getMetadatas('FlickrService' . $cacheKey);
if (!($result = $cache->load($cacheKey)) || $this->softCacheExpired($metadata['mtime'])) {
// try update the cache
try {
$result = call_user_func_array(array($this, $funcName), $args);
// only update cache if result returned
if ($result) {
$cache->save($result, $cacheKey);
}
} catch (Exception $e) {
SS_Log::log(sprintf("Couldn't retrieve Flickr photos using '%s': Message: %s", $funcName, $e->getMessage()), SS_Log::ERR);
}
}
return $result;
}
示例11: array
Config::inst()->update('Email', 'admin_email', $email_from);
//Register Shortcodes
ShortcodeParser::get()->register('Sched', array('Page', 'SchedShortCodeHandler'));
ShortcodeParser::get()->register('outlink', array('Page', 'ExternalLinkShortCodeHandler'));
ShortcodeParser::get()->register('icon', array('Page', 'IconShortCodeHandler'));
//cache configuration
/*
SS_Cache::add_backend('two-level', 'Two-Levels', array(
'slow_backend' => 'File',
'fast_backend' => 'Apc',
'slow_backend_options' => array('cache_dir' => TEMP_FOLDER . DIRECTORY_SEPARATOR . 'cache')
));
SS_Cache::pick_backend('two-level', 'any', 10); // No need for special backend for aggregate - TwoLevels with a File slow backend supports tags
*/
SS_Cache::add_backend('file-level', 'File', array('cache_dir' => TEMP_FOLDER . DIRECTORY_SEPARATOR . 'cache'));
SS_Cache::pick_backend('file-level', 'any', 10);
SS_Cache::set_cache_lifetime($for = 'cache_entity_count', $lifetime = 3600, $priority = 100);
//entity counter extension
Object::add_extension('HomePage_Controller', 'EntityCounter');
Object::add_extension('AnniversaryPage_Controller', 'EntityCounter');
Object::add_extension('Group', 'GroupDecorator');
Object::add_extension('SecurityAdmin', 'SecurityAdminExtension');
//Force cache to flush on page load if in Dev mode (prevents needing ?flush=1 on the end of a URL)
if (Director::isDev()) {
//Set default login
Security::setDefaultAdmin('admin', 'pass');
}
/* TinyMCE Configuration */
$tinyMCE = HtmlEditorConfig::get('cms');
$tinyMCE->setOption('extended_valid_elements', '@[id|class|style|title],#a[id|rel|rev|dir|tabindex|accesskey|type|name|href|target|title|class],-strong/-b[class],-em/-i[class],-strike[class],-u[class],#p[id|dir|class|align|style],-ol[class],-ul[class],-li[class],br,i,em,img[id|dir|longdesc|usemap|class|src|border|alt=|title|width|height|align],-sub[class],-sup[class],-blockquote[dir|class],-table[border=0|cellspacing|cellpadding|width|height|class|align|summary|dir|id|style],-tr[id|dir|class|rowspan|width|height|align|valign|bgcolor|background|bordercolor|style],tbody[id|class|style],thead[id|class|style],tfoot[id|class|style],#td[id|dir|class|colspan|rowspan|width|height|align|valign|scope|style],-th[id|dir|class|colspan|rowspan|width|height|align|valign|scope|style],caption[id|dir|class],-div[id|dir|class|align|style],-span[class|align|style],-pre[class|align|name],address[class|align],-h1[id|dir|class|align|style],-h2[id|dir|class|align|style],-h3[id|dir|class|align|style],-h4[id|dir|class|align|style],-h5[id|dir|class|align|style],-h6[id|dir|class|align|style],hr[class],dd[id|class|title|dir],dl[id|class|title|dir],dt[id|class|title|dir],@[id,style,class]');
示例12: Minify_Requirements_Backend
<?php
if (Director::isLive()) {
Controller::add_extension('SS_MinifiedResponseExtension');
Requirements::set_backend(new Minify_Requirements_Backend());
if (defined('MINIFY_CACHE_BACKEND') && defined('MINIFY_CACHE_LIFETIME')) {
$backend = unserialize(MINIFY_CACHE_BACKEND);
SS_Cache::add_backend('MINIFY_CACHE_BACKEND', $backend['Type'], $backend['Options']);
SS_Cache::set_cache_lifetime('MINIFY_CACHE_BACKEND', MINIFY_CACHE_LIFETIME, 100);
SS_Cache::pick_backend('MINIFY_CACHE_BACKEND', 'MINIFY_CACHE', 100);
}
}
示例13: array
<?php
ModelAdmin::add_extension("ImportAdminExtension");
ModelAdmin::add_extension("ExportAdminExtension");
$remove = Config::inst()->get('ModelAdmin', 'removelegacyimporters');
if ($remove === "scaffolded") {
Config::inst()->update("ModelAdmin", 'model_importers', array());
}
//cache mappings forever
SS_Cache::set_cache_lifetime('gridfieldimporter', null);
示例14: array
<?php
/**
*
* @author: Nicolaas - modules [at] sunnysideup.co.nz
**/
// optional settings that may be useful
//setlocale (LC_TIME, 'en_NZ@dollar', 'en_NZ.UTF-8', 'en_NZ', 'nz', 'nz');
//date_default_timezone_set("NZ");
// CACHING RECOMMENDATION - you can overrule that in the mysite _config.php file...
//one week = 604800 (60 * 60 * 24 * 7)
//last param is priority
SS_Cache::set_cache_lifetime('any', 604800);
CMSMenu::add_menu_item('refresh', 'Refresh Website', 'shoppingcart/clear/?flush=all', $controllerClass = null, $priority = 2.9, array("target" => "_blank"));
CMSMenu::remove_menu_item('CMSPageAddController_Products');
示例15: array
<?php
SS_Cache::add_backend('LatestTweets_cache', 'File', array('cache_dir' => TEMP_FOLDER . DIRECTORY_SEPARATOR . 'cache'));
SS_Cache::set_cache_lifetime('LatestTweets_cache', 1800, 10);
SS_Cache::pick_backend('LatestTweets_cache', 'any', 10);
Object::add_extension('SiteConfig', 'LaTw_SiteConfig_Extension');
Object::add_extension('Page_Controller', 'LaTw_Page_Controller_Extension');