本文整理汇总了PHP中modX::getCacheManager方法的典型用法代码示例。如果您正苦于以下问题:PHP modX::getCacheManager方法的具体用法?PHP modX::getCacheManager怎么用?PHP modX::getCacheManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类modX
的用法示例。
在下文中一共展示了modX::getCacheManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: conversationsMap
/**
* Create conversations map
*
* @return array|false False if cache is off
*/
public function conversationsMap()
{
/**
* If disabled caching return False
*/
if (!$this->modx->getCacheManager()) {
return false;
}
/**
* If a map is present in the cache, then just return it
*/
$map = $this->modx->cacheManager->get('conversations_map', array(xPDO::OPT_CACHE_KEY => 'modxtalks'));
if ($map) {
return $map;
}
/**
* If the map is not in the cache, we all topics from the database and build the map
*/
$map = array();
$c = $this->modx->newQuery('modxTalksConversation');
$c->select(array('id', 'rid', 'conversation'));
if ($c->prepare() && $c->stmt->execute()) {
$conversations = $c->stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($conversations as $c) {
$map[$c['rid']][$c['id']] = $c['conversation'];
}
$this->modx->cacheManager->set('conversations_map', $map, 0, array(xPDO::OPT_CACHE_KEY => 'modxtalks'));
}
return $map;
}
示例2: setCachePath
/**
* Sets the cache path for this Smarty instance
*
* @access public
* @param string $path The path to set. Defaults to '', which in turn
* defaults to $this->modx->cachePath.
*/
public function setCachePath($path = '')
{
$path = $this->modx->getOption(xPDO::OPT_CACHE_PATH) . $path;
if (!is_dir($path)) {
$this->modx->getCacheManager();
$this->modx->cacheManager->writeTree($path);
}
$this->compile_dir = $path;
}
示例3: translateFiles
/**
* Translate specific files
*
* @param boolean $save If true, will save the translation
* @param array $files An array of files to translate
* @return string
*/
public function translateFiles($save = false, $files = array())
{
$output = '';
if (is_array($files) && !empty($files)) {
$parser = $this->getParser();
$parser->tagTranslation = $this->tagTranslation;
$cacheManager = $this->modx->getCacheManager();
$output .= "Processing files: " . print_r($files, true) . "\n\n\n";
ob_start();
foreach ($files as $file) {
if (file_exists($file)) {
echo "[BEGIN TRANSLATING FILE] {$file}\n";
$content = file_get_contents($file);
if ($content !== false) {
$content = str_replace($this->preTranslationSearch, $this->preTranslationReplace, $content);
while ($parser->translate($content, array(), true)) {
}
if ($save) {
$cacheManager->writeFile($file, $content);
}
}
echo "[END TRANSLATING FILE] {$file}\n";
}
}
$output .= ob_get_contents();
ob_end_clean();
}
return $output;
}
示例4: move
/**
* Move a thread to a new board
*
* @param int $boardId
* @return boolean True if successful
*/
public function move($boardId)
{
$oldBoard = $this->getOne('Board');
$newBoard = is_object($boardId) && $boardId instanceof disBoard ? $boardId : $this->xpdo->getObject('disBoard', $boardId);
if (!$oldBoard || !$newBoard) {
return false;
}
$this->addOne($newBoard);
if ($this->save()) {
/* readjust all posts */
$posts = $this->getMany('Posts');
foreach ($posts as $post) {
$post->set('board', $newBoard->get('id'));
$post->save();
}
/* adjust old board topics/reply counts */
$oldBoard->set('num_topics', $oldBoard->get('num_topics') - 1);
$replies = $oldBoard->get('num_replies') - $this->get('replies');
$oldBoard->set('num_replies', $replies);
$total_posts = $oldBoard->get('total_posts') - $this->get('replies') - 1;
$oldBoard->set('total_posts', $total_posts);
/* recalculate latest post */
$oldBoardLastPost = $this->xpdo->getObject('disPost', array('id' => $oldBoard->get('last_post')));
if ($oldBoardLastPost && $oldBoardLastPost->get('id') == $this->get('post_last')) {
$newLastPost = $oldBoard->get2ndLatestPost();
if ($newLastPost) {
$oldBoard->set('last_post', $newLastPost->get('id'));
$oldBoard->addOne($newLastPost, 'LastPost');
}
}
$oldBoard->save();
/* adjust new board topics/reply counts */
$newBoard->set('num_topics', $oldBoard->get('num_topics') - 1);
$replies = $newBoard->get('num_replies') + $this->get('replies');
$newBoard->set('num_replies', $replies);
$total_posts = $newBoard->get('total_posts') + $this->get('replies') + 1;
$newBoard->set('total_posts', $total_posts);
/* recalculate latest post */
$newBoardLastPost = $this->xpdo->getObject('disPost', array('id' => $newBoard->get('last_post')));
$thisThreadPost = $this->getOne('LastPost');
if ($newBoardLastPost && $thisThreadPost && $newBoardLastPost->get('createdon') < $thisThreadPost->get('createdon')) {
$newBoard->set('last_post', $thisThreadPost->get('id'));
$newBoard->addOne($thisThreadPost, 'LastPost');
}
$newBoard->save();
/* Update ThreadRead board field */
$this->xpdo->exec('UPDATE ' . $this->xpdo->getTableName('disThreadRead') . '
SET ' . $this->xpdo->escape('board') . ' = ' . $newBoard->get('id') . '
WHERE ' . $this->xpdo->escape('thread') . ' = ' . $this->get('id') . '
');
/* clear caches */
if (!defined('DISCUSS_IMPORT_MODE')) {
$this->xpdo->getCacheManager();
$this->xpdo->cacheManager->delete('discuss/thread/' . $this->get('id'));
$this->xpdo->cacheManager->delete('discuss/board/' . $newBoard->get('id'));
$this->xpdo->cacheManager->delete('discuss/board/' . $oldBoard->get('id'));
}
}
return true;
}
示例5: push
/**
* Push a source to a specified target location.
*
* @param string $source A valid file or stream location source.
* @param string $target A valid file or stream location target.
*
* @return bool Returns true if the source was pushed successfully to the target, false otherwise.
*/
public function push($source, $target)
{
$pushed = false;
if ($this->modx->getCacheManager()) {
$pushed = $this->modx->cacheManager->copyFile($source, $target, array('copy_preserve_permissions' => true));
}
return $pushed;
}
示例6: getSettings
/**
* Grab settings (from cache if possible) as key => value pairs.
* @return array|mixed
*/
public function getSettings()
{
/* Attempt to get from cache */
$cacheOptions = array(xPDO::OPT_CACHE_KEY => 'system_settings');
$settings = $this->modx->getCacheManager()->get('clientconfig', $cacheOptions);
if (empty($settings) && $this->modx->getCount('cgSetting') > 0) {
$collection = $this->modx->getCollection('cgSetting');
$settings = array();
/* @var cgSetting $setting */
foreach ($collection as $setting) {
$settings[$setting->get('key')] = $setting->get('value');
}
/* Write to cache again */
$this->modx->cacheManager->set('clientconfig', $settings, 0, $cacheOptions);
}
return is_array($settings) ? $settings : array();
}
示例7: setCache
/**
* Sets data to cache
*
* @param mixed $data
* @param mixed $options
*
* @return string $cacheKey
*/
public function setCache($data = array(), $options = array())
{
$cacheKey = $this->getCacheKey($options);
$cacheOptions = $this->getCacheOptions($options);
if (!empty($cacheKey) && !empty($cacheOptions) && $this->modx->getCacheManager()) {
$this->modx->cacheManager->set($cacheKey, $data, $cacheOptions[xPDO::OPT_CACHE_EXPIRES], $cacheOptions);
$this->addTime('Saved data to cache "' . $cacheOptions[xPDO::OPT_CACHE_KEY] . '/' . $cacheKey . '"');
}
return $cacheKey;
}
示例8: clearCache
/**
* @param array $options
*
* @return bool
*/
public function clearCache($options = array())
{
$cacheKey = $this->getCacheKey($options);
$cacheOptions = $this->getCacheOptions($options);
if (!empty($cacheKey)) {
$cacheOptions['cache_key'] .= $cacheKey;
}
if (!empty($cacheOptions) and $this->modx->getCacheManager()) {
return $this->modx->cacheManager->clean($cacheOptions);
}
return false;
}
示例9: loadCache
public static function loadCache(modX $modx)
{
if (!$modx->getCacheManager()) {
return array();
}
$cacheKey = 'namespaces';
$cache = $modx->cacheManager->get($cacheKey, array(xPDO::OPT_CACHE_KEY => $modx->getOption('cache_namespaces_key', null, 'namespaces'), xPDO::OPT_CACHE_HANDLER => $modx->getOption('cache_namespaces_handler', null, $modx->getOption(xPDO::OPT_CACHE_HANDLER)), xPDO::OPT_CACHE_FORMAT => (int) $modx->getOption('cache_namespaces_format', null, $modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP))));
if (empty($cache)) {
$cache = $modx->cacheManager->generateNamespacesCache($cacheKey);
}
return $cache;
}
示例10: send
/**
* @param mixed $payload
* @param array $options
*/
public function send($payload, $options = array(), $metadata = array())
{
// return the original data
$return = $payload;
// set to project specified in MODX system settings
if (!isset($options['project'])) {
$options['project'] = $this->project;
}
// if empty metadata, do a backtrace
if (empty($metadata)) {
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
$backtrace = array_shift($backtrace);
$metadata['file'] = $backtrace['file'];
$metadata['line'] = $backtrace['line'];
}
// fix array keys to match phpconsole api
if (isset($metadata['file'])) {
$metadata['fileName'] = $metadata['file'];
unset($metadata['file']);
}
if (isset($metadata['line'])) {
$metadata['lineNumber'] = $metadata['line'];
unset($metadata['line']);
}
// if $payload is a xPDO Object, convert it to an array
if ($payload instanceof xPDOObject) {
$payload = $payload->toArray();
}
// make sure phpconsole was initialized
if (!$this->phpconsole) {
// save to normal error log file if phpconsole is not available
if ($this->modx->getCacheManager()) {
$filepath = $this->modx->getCachePath() . xPDOCacheManager::LOG_DIR . 'error.log';
$this->modx->cacheManager->writeFile($filepath, var_export($payload, true) . "\n", 'a');
}
} else {
// call send method of phpconsole
try {
$this->phpconsole->send($payload, $options, $metadata);
} catch (Exception $e) {
if ($this->modx->getCacheManager()) {
$filepath = $this->modx->getCachePath() . xPDOCacheManager::LOG_DIR . 'error.log';
$this->modx->cacheManager->writeFile($filepath, '[Phpconsole] Exception ' . $e->getCode() . ': ' . $e->getMessage() . "\n", 'a');
}
}
}
return $return;
}
示例11: loadCache
/**
* Loads a lexicon topic from the cache. If not found, tries to generate a
* cache file from the database.
*
* @access public
* @param string $namespace The namespace to load from. Defaults to 'core'.
* @param string $topic The topic to load. Defaults to 'default'.
* @param string $language The language to load. Defaults to 'en'.
* @return array The loaded lexicon array.
*/
public function loadCache($namespace = 'core', $topic = 'default', $language = '')
{
if (empty($language)) {
$language = $this->modx->getOption('cultureKey', null, 'en');
}
$key = $this->getCacheKey($namespace, $topic, $language);
$enableCache = $namespace != 'core' && !$this->modx->getOption('cache_noncore_lexicon_topics', null, true) ? false : true;
if (!$this->modx->cacheManager) {
$this->modx->getCacheManager();
}
$cached = $this->modx->cacheManager->get($key, array(xPDO::OPT_CACHE_KEY => $this->modx->getOption('cache_lexicon_topics_key', null, 'lexicon_topics'), xPDO::OPT_CACHE_HANDLER => $this->modx->getOption('cache_lexicon_topics_handler', null, $this->modx->getOption(xPDO::OPT_CACHE_HANDLER)), xPDO::OPT_CACHE_FORMAT => (int) $this->modx->getOption('cache_lexicon_topics_format', null, $this->modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP))));
if (!$enableCache || $cached == null) {
$results = false;
/* load file-based lexicon */
$results = $this->getFileTopic($language, $namespace, $topic);
if ($results === false) {
/* default back to en */
$results = $this->getFileTopic('en', $namespace, $topic);
if ($results === false) {
$results = array();
}
}
/* get DB overrides */
$c = $this->modx->newQuery('modLexiconEntry');
$c->innerJoin('modNamespace', 'Namespace');
$c->where(array('modLexiconEntry.topic' => $topic, 'modLexiconEntry.language' => $language, 'Namespace.name' => $namespace));
$c->sortby($this->modx->getSelectColumns('modLexiconEntry', 'modLexiconEntry', '', array('name')), 'ASC');
$entries = $this->modx->getCollection('modLexiconEntry', $c);
if (!empty($entries)) {
/** @var modLexiconEntry $entry */
foreach ($entries as $entry) {
$results[$entry->get('name')] = $entry->get('value');
}
}
if ($enableCache) {
$cached = $this->modx->cacheManager->generateLexiconTopic($key, $results);
} else {
$cached = $results;
}
}
if (empty($cached)) {
$this->modx->log(xPDO::LOG_LEVEL_DEBUG, "An error occurred while trying to cache {$key} (lexicon/language/namespace/topic)");
}
return $cached;
}
示例12: isset
// include 'mycomponentproject.class.php';
require_once $modx->getOption('mc.core_path', null, $modx->getOption('core_path') . 'components/mycomponent/') . 'model/mycomponent/mycomponentproject.class.php';
$props = isset($scriptProperties) ? $scriptProperties : array();
$project = new MyComponentProject($modx);
$project->init($props);
//$project->removeObjects();
$dryRun = false;
/* true is the default -- set to false for actual import */
/* Comma-separated list of elements to process (snippets,plugins,chunks,templates) */
$toProcess = 'snippets,plugins,chunks,templates';
/* path to elements directory to import -- if empty, project's elements dir will be used */
/*$directory = $modx->getOption('mc.core', null,
$modx->getOption('core_path') . 'components/example/') . 'elements/';*/
$directory = '';
$project->importObjects($toProcess, $directory, $dryRun);
$cm = $modx->getCacheManager();
$cm->refresh();
// echo print_r(ObjectAdapter::$myObjects, true);
$output = $project->helpers->getOutput();
$output .= "\n\n" . $modx->lexicon('mc_initial_memory_used') . ': ' . round($mem_usage / 1048576, 2) . ' ' . $modx->lexicon('mc_megabytes');
$mem_usage = memory_get_usage();
$peak_usage = memory_get_peak_usage(true);
$output .= "\n" . $modx->lexicon('mc_final_memory_used') . ': ' . round($mem_usage / 1048576, 2) . ' ' . $modx->lexicon('mc_megabytes');
$output .= "\n" . $modx->lexicon('mc_peak_memory_used') . ': ' . round($peak_usage / 1048576, 2) . ' ' . $modx->lexicon('mc_megabytes');
/* report how long it took */
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$tend = $mtime;
$totalTime = $tend - $tstart;
$totalTime = sprintf("%2.4f s", $totalTime);
示例13: transferPackage
/**
* Transfers the package from one directory to another.
*
* @access public
* @param string $sourceFile The file to transfer.
* @param string $targetDir The directory to transfer into.
* @return boolean True if successful.
*/
public function transferPackage($sourceFile, $targetDir)
{
$transferred = false;
$content = '';
if (is_dir($targetDir) && is_writable($targetDir)) {
if (!is_array($this->xpdo->version)) {
$this->xpdo->getVersionData();
}
$productVersion = $this->xpdo->version['code_name'] . '-' . $this->xpdo->version['full_version'];
$source = $this->get('service_url') . $sourceFile . (strpos($sourceFile, '?') !== false ? '&' : '?') . 'revolution_version=' . $productVersion;
/* see if user has allow_url_fopen on and is not behind a proxy */
$proxyHost = $this->xpdo->getOption('proxy_host', null, '');
if (ini_get('allow_url_fopen') && empty($proxyHost)) {
if ($handle = @fopen($source, 'rb')) {
$filesize = @filesize($source);
$memory_limit = @ini_get('memory_limit');
if (!$memory_limit) {
$memory_limit = '8M';
}
$byte_limit = $this->_bytes($memory_limit) * 0.5;
if (strpos($source, '://') !== false || $filesize > $byte_limit) {
$content = @file_get_contents($source);
} else {
$content = @fread($handle, $filesize);
}
@fclose($handle);
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $this->xpdo->lexicon('package_err_file_read', array('source' => $source)));
}
/* if not, try curl */
} else {
if (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $source);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 180);
$safeMode = @ini_get('safe_mode');
$openBasedir = @ini_get('open_basedir');
if (empty($safeMode) && empty($openBasedir)) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
}
$proxyHost = $this->xpdo->getOption('proxy_host', null, '');
if (!empty($proxyHost)) {
$proxyPort = $this->xpdo->getOption('proxy_port', null, '');
curl_setopt($ch, CURLOPT_PROXY, $proxyHost);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxyPort);
$proxyUsername = $this->xpdo->getOption('proxy_username', null, '');
if (!empty($proxyUsername)) {
$proxyAuth = $this->xpdo->getOption('proxy_auth_type', null, 'BASIC');
$proxyAuth = $proxyAuth == 'NTLM' ? CURLAUTH_NTLM : CURLAUTH_BASIC;
curl_setopt($ch, CURLOPT_PROXYAUTH, $proxyAuth);
$proxyPassword = $this->xpdo->getOption('proxy_password', null, '');
$up = $proxyUsername . (!empty($proxyPassword) ? ':' . $proxyPassword : '');
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $up);
}
}
$content = curl_exec($ch);
curl_close($ch);
/* and as last-ditch resort, try fsockopen */
} else {
$content = $this->_getByFsockopen($source);
}
}
if ($content) {
if ($cacheManager = $this->xpdo->getCacheManager()) {
$filename = $this->signature . '.transport.zip';
$target = $targetDir . $filename;
$transferred = $cacheManager->writeFile($target, $content);
}
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'MODX could not download the file. You must enable allow_url_fopen, cURL or fsockopen to use remote transport packaging.');
}
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $this->xpdo->lexicon('package_err_target_write', array('targetDir' => $targetDir)));
}
return $transferred;
}
示例14:
/**
* @param modX $modx
*/
function __construct(modX $modx)
{
$this->modx =& $modx;
$this->cacheManager = $modx->getCacheManager();
}
示例15: clearCache
/**
* Clear the cache for this User
*
* @return void
*/
public function clearCache()
{
if (!defined('DISCUSS_IMPORT_MODE')) {
$this->xpdo->getCacheManager();
$this->xpdo->cacheManager->delete('discuss/user/' . $this->get('id'));
$this->xpdo->cacheManager->delete('discuss/board/user/' . $this->get('id'));
}
}