Search code examples
javascalacachingcache-controlplayframework-2.0

Playframework 2.x - prevent assets caching


I'm using playframework v2 and I have my sitemap files being re-created once a day by an external process. They're all in the assets folder/sitemap

How do I force playframework to return the file directly from disk?


Solution

  • You should get the file (from disk or WS) and render the content in a classic Action, then set the cache with an annotation :

    @Cached(key="sitemap", duration=86400)
    public static Result index() {
      // ... set sitemap variable from your file
      return ok(siteMap);
    }
    

    http://www.playframework.org/documentation/2.0/JavaCache

    Or you can achieve the same behavior with a job.