Class TopLevelCache

java.lang.Object
services.moleculer.service.MoleculerComponent
services.moleculer.service.Service
services.moleculer.web.middleware.HttpMiddleware
services.moleculer.web.middleware.TopLevelCache
All Implemented Interfaces:
services.moleculer.service.MoleculerLifecycle, HttpConstants

public class TopLevelCache extends HttpMiddleware implements HttpConstants
URL-based content cache. It is good for caching the responses of non-authenticated REST services with large responses. For example, if the service generates blog/wiki content using a HTML Template Egine. It is not advisable to cache POST requests and/or requests that depend not only on the URL but also on the content of the request. TopLevelCache speeds up querying of various reports (tables, charts) and dynamically generated images. Sample:
restRoute.use(new TopLevelCache("/blog/posts/**"));
  • Field Details

    • logger

      protected static final org.slf4j.Logger logger
    • pathCache

      protected final io.datatree.dom.Cache<String,Boolean> pathCache
    • cacher

      protected final services.moleculer.cacher.Cacher cacher
    • region

      protected String region
      Cache region (~= prefix).
    • ttl

      protected int ttl
      Expire time, in SECONDS (0 = never expires)
    • pathPatterns

      protected String[] pathPatterns
    • useETags

      protected boolean useETags
      Use ETag headers
  • Constructor Details

    • TopLevelCache

      public TopLevelCache(services.moleculer.cacher.Cacher cacher, String... pathPatterns)
  • Method Details

    • install

      public RequestProcessor install(RequestProcessor next, io.datatree.Tree config)
      Specified by:
      install in class HttpMiddleware
    • getRegion

      public String getRegion()
    • setRegion

      public void setRegion(String region)
    • getTtl

      public int getTtl()
    • setTtl

      public void setTtl(int ttl)
    • getPathPatterns

      public String[] getPathPatterns()
    • setPathPatterns

      public void setPathPatterns(String... pathPatterns)
    • addPathPattern

      public TopLevelCache addPathPattern(String... pathPatterns)