Search code examples
suave

How do I tell Suave not to cache a url?


I have 2 paths getting cached

Auth.loggedOn (
    GET >=>
        pathScan "/era/%i" (Some >> EraViewing.eraView homeFolder cn)
        path "/" >=> indexView homeFolder cn

There is a x.html file behind each of these which get served after replacing some templated parts.

Which are getting cached, but I do not want them to. how can I tell suave not ?


Not the same question, as that one is solved by making something a function rather than telling suave not to cache or when to recalcuate/reevaluate a url


Solution

  • To indicate the browser to not cache the response you can define the following combinator.

    let noCache = 
      setHeader "Cache-Control" "no-cache, no-store, must-revalidate"
      >=> setHeader "Pragma" "no-cache"
      >=> setHeader "Expires" "0"
    

    And use it like in the following

    let app = OK "Hello" >=> noCache