t3blog - 用户写评论时如何清除缓存?

发布于 2024-10-31 17:19:45 字数 334 浏览 7 评论 0原文

当用户写评论时,评论不会立即可见。如果我手动清除缓存,它就会变得可见。


通常 t3blog 将帖子和评论存储在 t3blog 页面本身中,然后应该能够通过这种方式清除缓存。

TCEMAIN.clearCacheCmd = all

然而,在我的 t3blog 设置中,帖子和评论位于单独的 sys 文件夹中。这是设置打字稿

plugin.tx_t3blog_pi1.blogPid = 21

有没有办法在用户提交新评论时触发清除缓存?

When a user writes a comment then it doesn't become visible right away. It becomes visible if I clear the cache manually.


Usually t3blog stores posts and comments within the t3blog page itself and then one should be able to clear the cache this way.

TCEMAIN.clearCacheCmd = all

However in my t3blog setup the posts and comments are in a separate sysfolder. Here is the setup typoscript

plugin.tx_t3blog_pi1.blogPid = 21

Is there a way I can trigger clear cache when the user submits a new comment?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

以可爱出名 2024-11-07 17:19:45

我尝试安装“aftercommentinsertion”挂钩未成功。

最后我通过修改t3blog本身解决了这个问题,这样就可以通过typoscript指定需要清除的页面的uid。

# my typoscript code
plugin.tx_t3blog_pi1.blogList {

    # clear these pages when a visitor writes a new comment to a post
    clearCacheForPIDsAfterCommentInsertion = 1,6,8,24
}




// the file: t3blog/pi1/widgets/blogList/class.singleFunctions.php
protected function insertNewComment(array $data) {
    $data['pid'] = t3blog_div::getBlogPid();
    $data['date'] = $data['crdate'] = $GLOBALS['EXEC_TIME'];
    $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_t3blog_com', $data);
    $commendId = $GLOBALS['TYPO3_DB']->sql_insert_id();
    $this->updateRefIndex('tx_t3blog_com', $commentId);

    // Hook after comment insertion
    if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3blog']['aftercommentinsertion'])) {
        foreach($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3blog']['aftercommentinsertion'] as $userFunc) {
            $params = array(
                'data' => &$data,
                'table' => 'tx_t3blog_com',
                'postUid' => $data['fk_post'],
                'commentUid' => $commendId,
            );
            t3lib_div::callUserFunction($userFunc, $params, $this);
        }
    }


    // ******************* MY CLEAR CACHE CODE *******************
    error_log("t3blog inserted new comment");
    $pids = $this->conf['clearCacheForPIDsAfterCommentInsertion'];
    $pidArray = is_string($pids) ? t3lib_div::trimExplode(',', $pids, 1) : NULL;
    error_log("t3blog clearCacheForPIDsAfterCommentInsertion: ".$pids."   --   ".print_r($pidArray, true));
    if(is_array($pidArray)) {
        $tce = t3lib_div::makeInstance('t3lib_TCEmain');
        foreach($pidArray as $pid) { 
            error_log("t3blog clear_cacheCmd: ".$pid);
            $tce->clear_cacheCmd((int)$pid); 
        }
    }

}

我已将此代码发送给 Dmitry Dulepov(t3blog 的作者)。

I have unsuccessfully tried installing an 'aftercommentinsertion' hook.

Finally I solved it by modifying t3blog itself, so that you can specify the uid of the pages that needs to be cleared via typoscript.

# my typoscript code
plugin.tx_t3blog_pi1.blogList {

    # clear these pages when a visitor writes a new comment to a post
    clearCacheForPIDsAfterCommentInsertion = 1,6,8,24
}




// the file: t3blog/pi1/widgets/blogList/class.singleFunctions.php
protected function insertNewComment(array $data) {
    $data['pid'] = t3blog_div::getBlogPid();
    $data['date'] = $data['crdate'] = $GLOBALS['EXEC_TIME'];
    $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_t3blog_com', $data);
    $commendId = $GLOBALS['TYPO3_DB']->sql_insert_id();
    $this->updateRefIndex('tx_t3blog_com', $commentId);

    // Hook after comment insertion
    if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3blog']['aftercommentinsertion'])) {
        foreach($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3blog']['aftercommentinsertion'] as $userFunc) {
            $params = array(
                'data' => &$data,
                'table' => 'tx_t3blog_com',
                'postUid' => $data['fk_post'],
                'commentUid' => $commendId,
            );
            t3lib_div::callUserFunction($userFunc, $params, $this);
        }
    }


    // ******************* MY CLEAR CACHE CODE *******************
    error_log("t3blog inserted new comment");
    $pids = $this->conf['clearCacheForPIDsAfterCommentInsertion'];
    $pidArray = is_string($pids) ? t3lib_div::trimExplode(',', $pids, 1) : NULL;
    error_log("t3blog clearCacheForPIDsAfterCommentInsertion: ".$pids."   --   ".print_r($pidArray, true));
    if(is_array($pidArray)) {
        $tce = t3lib_div::makeInstance('t3lib_TCEmain');
        foreach($pidArray as $pid) { 
            error_log("t3blog clear_cacheCmd: ".$pid);
            $tce->clear_cacheCmd((int)$pid); 
        }
    }

}

I have sendt this code to Dmitry Dulepov (the author of t3blog).

甜`诱少女 2024-11-07 17:19:45

您可以在保存您的博客文章的 sysfolder (uid=21) 的 PAGE TS 中添加此行:

TCEMAIN.clearCacheCmd = 1,6,8,24

该行将告诉新的博客文章将触发该确切页面列表的清除缓存。我认为您的用户需要清除缓存的权限...

它进入您的系统文件夹的 PAGE TS 而不是插入您的博客的一个或所有页面的原因是...它们(可能)都被缓存了。您的 sysfolder 未缓存,新记录将被 TYPO3 注意到,并欺骗您刚刚通过逗号分隔字符串定义的缓存页面的清除缓存。

You can add this line in your PAGE TS of the sysfolder (uid=21) holding your blog post:

TCEMAIN.clearCacheCmd = 1,6,8,24

That line will tell that new blog posts shall trigger a clear cache of that exact list of pages. I think your users will need rights to clear cache though...

Reason it goes into the PAGE TS of you sysfolder and not one or all of the pages where your blog is inserted is that... they are (probably) all cached. Your sysfolder is not cached and the new record will be noticed by TYPO3 and tricker a clear cache of the cached pages you just defined by your comma separated string.

开始看清了 2024-11-07 17:19:45

您是否尝试将clearCacheCmd包含在存储注释的sys文件夹的页面TSconfig中?您可以使用“全部”、“页面”或相关页面 uid,参见:http://typo3.org/documentation/document-library/core-documentation/doc_core_tsconfig/4.3.2/view/1/5/#id2505694

这应该如果“用户”是具有相关权限的后端用户,则可以工作 - 但我想,当你说“用户写评论”时,它是你正在谈论的前端用户,然后这可能不会有太大影响帮助。

解决方案是让扩展程序在收到评论后清除缓存。您可能无法做到这一点,但快速解决此问题的方法是将页面标记为不可缓存(“禁用缓存”,“行为”选项卡)。但请注意,这会导致您的服务器受到影响。

Did you try to include the clearCacheCmd in the page TSconfig of the sysfolder where the comments are stored? You can use "all", "pages" or the relevant page uids, cf: http://typo3.org/documentation/document-library/core-documentation/doc_core_tsconfig/4.3.2/view/1/5/#id2505694

This should work if the "user" is a backend user with the relevant priveleges - but I guess, when you say "a user writes a comment", it is a front end user you are talking about, and then this will probably not be of much help.

The solution then would be to have the extension clear the cache upon receiving a comment. This might not be possible for you to do, but the quick fix to this is to mark the page as not cacheable ("Disable cache", Behavior tab). Beware, though, this will cause your server to suffer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文