Boost C++ Libraries

PrevUpHomeNext

Struct cache_rule

boost::taar::handler::cache_rule — A Cache-Control rule of htdocs_options::cache_rules.

Synopsis

// In header: <boost/taar/handler/htdocs.hpp>


struct cache_rule {

  // public static functions
  static cache_rule glob(std::string, std::string);

  // public data members
  std::function< bool(std::string_view)> match;  // Predicate on the relative path. 
  std::string value;  // The Cache-Control value sent when match accepts the path. 
};

Description

Rules are tried in order on the served file's decoded path relative to the root (no leading slash, e.g. assets/app.3f9a1c2e.js); the first whose match returns true supplies the header value.

options.cache_rules = {
    taar::handler::cache_rule::glob("*.woff2", "public, max-age=86400"),
    {[](std::string_view p) { return p.ends_with(".html"); }, "no-cache"},
};

cache_rule public static functions

  1. static cache_rule glob(std::string pattern, std::string value);
    A rule matching a glob pattern (see cache_rules::glob_match).

    Parameters:

    pattern

    * matches within a segment, ** across segments, ? one character. A pattern without / is matched against the file name only (*.css matches a/b/site.css).

    value

    The Cache-Control value.


PrevUpHomeNext