drgbpq5930 2015-07-16 07:37
浏览 41
已采纳

Revel框架中的缓存失效

I'm looking for a way to invalidate cached static content upon version change. Preferably using commit id to invalidate. Is there anyway to do this in revel framework ?

I would prefer if its automatic but I could live with updating it each time if its a single place I have to edit.

The current strategy I have is changing the name of the static content route to include version but this requires several changes. In places that feel unnatural, for instance in the routing file.

  • 写回答

2条回答 默认 最新

  • duanshan3427 2015-07-16 09:16
    关注

    You could do it manually via a config variable and an intercept method.

    resourceversion.go

    Create this file in your controllers folder:

    package controllers
    
    import (
        "github.com/revel/revel"
    )
    
    // interceptor method, called before every request. 
    // Sets a template variable to the resourceVersion read from app.conf
    func SetVersion(c *revel.Controller) revel.Result {
        c.RenderArgs["resourceVersion"] = revel.Config.StringDefault("resourceVersion", "1")
        return nil
    }
    

    init.go

    In the init() method, append this line:

    revel.InterceptMethod(controllers.SetVersion, revel.BEFORE)
    

    templates

    In your templates, where you want to use the resource version:

    <link rel="stylesheet" type="text/css" href="/public/css/style.css?{{.resourceVersion}}">
    

    app.conf

    And finally, the place you will update it - add this line above the dev section to apply to dev and prod, or have a different one in each, whatever suits.

    resourceVersion=20150716
    

    I guess you could create a script as part of your build and release process that would automatically edit this config variable.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么