【问题标题】:Caching django cms CustomPlugin缓存 django cms CustomPlugin
【发布时间】:2016-11-02 20:49:43
【问题描述】:

我正在使用 DjangoCMS 开发一个网站,完全可以使用 CustomPlugins 进行前端编辑。

我想知道是否有任何解决方法可以不缓存特定占位符内的插件。

假设我有一个 CustomPlugin,我希望这个插件可以缓存到任何地方,除非它在 ​​{% static_placeholder 'special_placeholder' %}
我的 CustomPlugin 定义中的 cache = False 标志没有做我想要的(我希望这个插件是否被缓存,具体取决于它包含的占位符)。全局设置 CMS_PLUGIN_CACHECMS_PLACEHOLDER_CACHE 不符合我的需求,因为它们相同。

如果您能给我一些建议,我将非常感激。

【问题讨论】:

    标签: django caching django-cms django-cache


    【解决方案1】:

    您可以直接在插件类中控制它

    class YourPlugin(CMSPluginBase):
       model = YourCustomPluginModel
       render_template = 'yourapp/yourtemplate.html'
    
       def render(self, context, instance, placeholder):
           # you can cache "your_data" depending on 'placeholder' here
    
           context.update({
               'instance': instance,
               'placeholder': placeholder,
               'your_data': your_data
           })
           return context
    

    plugin_pool.register_plugin(YourPlugin)

    【讨论】:

    • 感谢您的回答。但是如果插件被缓存,则不会调用render 方法。我已经在render 中设置了一些上下文变量,但是由于插件被缓存,所以没有存储,这取决于插件是否在缓存中。
    • @ÁlvaroLamasFuente 这是不可能的。您要么缓存整个插件,要么删除缓存并在render中自行缓存上下文@
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 2015-11-12
    • 1970-01-01
    相关资源
    最近更新 更多