简体   繁体   English

TYPO3:计算缓存标识符哈希值?

[英]TYPO3: Calculate Cache identifier hash value?

In TYPO3 I want to remove a single page from the cache table with some GET values. 在TYPO3中,我想从缓存表中删除一些具有GET值的页面。 I haven't found an extension, that will handle that or a TYPO3 method. 我还没有找到可以处理该扩展或TYPO3方法的扩展。

  1. Is there a function, that I can hand over a URL or similar, that produces the cache hash identifier or removes the specific data from the caching tables? 是否有一个我可以移交URL或类似名称的函数来生成高速缓存哈希标识符或从高速缓存表中删除特定数据?
  2. If not, does anybody know, what the algorithm is, that calculates the hash identifier or in which file I might find it? 如果不是,那么有人知道算法是什么,它可以计算哈希标识符,或者可以在哪个文件中找到它?

So any help will be appreciated. 因此,任何帮助将不胜感激。

My TYPO3 version: 4.5.x 我的TYPO3版本:4.5.x

You can create a function which clear the cache of a specified page, following code is needed: 您可以创建一个函数来清除指定页面的缓存,需要以下代码:

TYPO3 6.0 TYPO3 6.0

public function clearCache($cacheCmd) {
    /** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */
    $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance("TYPO3\\CMS\\Core\\DataHandling\\DataHandler");
    $tce->stripslashes_values = 0;
    $tce->start(array(), array());

    switch($cacheCmd) {
        case 'pages':
        case 'all':
            $tce->admin = 1;
    }

    $tce->clear_cacheCmd($cacheCmd);
    unset($tce);
}

TYPO3 4.x TYPO3 4.x

public function clearCache($cacheCmd) {
    /** @var $tce t3lib_TCEmain */
    $tce = t3lib_div::makeInstance("t3lib_TCEmain");
    $tce->stripslashes_values = 0;
    $tce->start(array(), array());

    switch($cacheCmd) {
        case 'pages':
        case 'all':
            $tce->admin = 1;
    }

    $tce->clear_cacheCmd($cacheCmd);
    unset($tce);
}

And $cacheCmd can have following values: /typo3/sysext/core/Classes/DataHandling/DataHandler.php:clear_cacheCmd (> 6.0) or /t3lib/class.t3lib_tcemain.php (4.x) $cacheCmd可以具有以下值: /typo3/sysext/core/Classes/DataHandling/DataHandler.php:clear_cacheCmd : /typo3/sysext/core/Classes/DataHandling/DataHandler.php:clear_cacheCmd (> 6.0)或/t3lib/class.t3lib_tcemain.php

/**
 * Clears the cache based on the command $cacheCmd.
 *
 * $cacheCmd='pages':   Clears cache for all pages. Requires admin-flag to
 * be set for BE_USER.
 *
 * $cacheCmd='all':     Clears all cache_tables. This is necessary if
 * templates are updated. Requires admin-flag to be set for BE_USER.
 *
 * $cacheCmd=[integer]: Clears cache for the page pointed to by $cacheCmd
 * (an integer).
 *
 * $cacheCmd='cacheTag:[string]':  Flush page and pagesection cache by given tag
 *
 * $cacheCmd='cacheId:[string]':  Removes cache identifier from page and page section cache
 *
 * Can call a list of post processing functions as defined in
 * $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc']
 * (numeric array with values being the function references, called by
 * \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction()).
 *
 * Note: The following cache_* are intentionally not cleared by
 * $cacheCmd='all':
 *
 * - cache_md5params:   RDCT redirects.
 * - cache_imagesizes:  Clearing this table would cause a lot of unneeded
 * Imagemagick calls because the size informations have
 * to be fetched again after clearing.
 *
 * @param string $cacheCmd The cache command, see above description
 * @return void
 */

Call this with a userFunc if a given parameter is set in typoscript or create a simple extension by your own. 如果在打字错误中设置了给定的参数,请使用userFunc调用此函数,或者由您自己创建一个简单的扩展名。

It's like this: 就像这样:

You need a proper TSFE object $GLOBALS['TSFE'] 您需要一个适当的TSFE对象$GLOBALS['TSFE']
then you need the encryption key from the localconf $TYPO3_CONF_VARS['SYS']['encryptionKey'] and the URL parameters eg `tx_ttnews[tt_news] 那么您需要来自localconf $TYPO3_CONF_VARS['SYS']['encryptionKey']和URL参数,例如'tx_ttnews [tt_news]

then these steps 然后这些步骤

  1. create an (sorted) array with the encryption key and the url parameters 使用加密密钥和url参数创建一个(排序的)数组
  2. Hand over this array to the property cHash_array of the TSFE object 将此数组移交给TSFE对象的属性cHash_array
  3. Get the cHash value from the TSFE's getHash method 从TSFE的getHash方法获取cHash值

$arr = array(
    'encryptionKey' => $TYPO3_CONF_VARS['SYS']['encryptionKey'],
    'tx_ttnews[tt_news]' => $newsid,
    // ...
)
ksort($array);
$GLOBALS['TSFE']->cHash_array = $array;
$chash = $GLOBALS['TSFE']->getHash();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM