Moovweb’s cloud infrastructure includes an Edge Caching layer that sits between your users and your project’s t.engine. This caching layer can be accessed by including Moovweb’s Cache Mixer in your Moovweb project. Once enabled, the Edge Caching layer will respect any caching headers that your origin website has, and will also give you the ability to modify cache headers to suit your transformed website. You can improve the performance of your mobile website and decrease the load on your origin servers by letting Moovweb respond quickly to your users.
This product feature is only available on the Enterprise Tier. You can test it in local development, but you will need to be on an Enterprise t.engine to use Edge Caching on a live site.
This diagram provides a high-level overview of Moovweb’s global cloud infrastructure and shows the data flow between your users and your origin web application.
Incoming requests are routed to the Moovweb datacenter closest to the end user which ensures that any cached content is served quickly to your users. Normally, every request received by Moovweb is sent upstream to the Origin Web Application, and the response is transformed based on the rules specified in your project.
When Edge Caching is enabled, Moovweb checks to see if the requested content is specified as cacheable; if so, Moovweb does not make an upstream request to the Origin Web Application. As a result, the usual transformations in the t.engine are not necessary. Instead, previously cached and transformed content is immediately sent back to your users.
Moovweb’s Edge Caching layer looks at specific HTTP headers to determine if the response should be cached or not. HTTP caching headers are special fields sent in an HTTP response that will determine what happens to the response along the entire request/response chain over the Internet. These headers are the rules that your browser follows to determine how long to keep any cached content, and they are the same ones followed by Moovweb. Please check out our References for details on the various headers.
There are many different cache headers covered in the HTTP specs, but the primary one that Moovweb looks at is the Cache-Control header. If the origin response does not have this header, the Edge Caching layer will not cache the response.
The Edge Caching layer will pass along original response headers and/or set additional headers to indicate that the response has been cached. There are two key headers to pay attention to in the final response from Moovweb:
Cache-Control: public, max-age=432000000allows all caches to store this response (public). This file is fresh until 13.5+ years from now (432,000,000 seconds). Please note that the Cache-Control header is typically passed through from the origin response.
Age: 15indicates the file has been cached for 15 seconds.
The Cache Mixer provides various functions to manage the Edge Caching layer. The main function you’ll use is called
cache.enable() and it will respect any cache headers that your origin response has.
If your origin response has Set-Cookie headers, it means the application is sending user-specific information to be stored on the user’s browser. This typically means you should not cache this response. If you still wish to enable caching on such responses, use the
cache.force() function which will delete the Set-Cookie headers and cache the response.
force() function with care. Removing any Set-Cookie headers could dramatically change the behavior of your application.
cache.force_for() functions will remove these cache headers from the origin response (if they exist):
It will then set a new Cache-Control header with the time specified. For example,
cache.enable_for("120") will set the header:
Cache-Control: public, max-age=120 and the response will be cached for 120 seconds.
force_for() function with care. Removing the original
Cache headers could dramatically change the behavior of your application.
Your project’s cache is cleared globally every time you push your code.
In certain cases, you may want to discard the contents of the cache manually. This feature is available in the Settings > Admin section of your project in the Control Center.
Please see the Advanced Use Cases page for more information.
You can turn on Edge Caching by adding Moovweb’s Cache Mixer to your project and using the appropriate functions. When you use the Cache Mixer, your project will add a new header to outgoing responses that should be cached:
During local development, you can see this X-Moov-Cache header. However, in production in the Moovweb Cloud, this header will be removed.
There is currently no support for varying the cache by User-Agent. Varying by User-Agent is not supported because it results in immense cache fragmentation — User-Agent strings differ so much from device to device that you’d need to keep a very large number of different copies of the response.
Moovweb’s Edge Caching layer caches a page by using the hostname and the URL to create a unique hash for the cache.
You can control the amount of time your blog homepage stays fresh in the Edge Caching layer by setting the
max-age value in the Cache-Control header. For example, for a page with
Cache-Control: public, max-age=1200, the cached page expires in 20 minutes (1200 seconds). Once the page expires, the request for your blog homepage is forwarded to the origin server, and the fresh updated page from your server then gets stored in the cache.
The Edge Caching layer typically speeds up Time To First Byte (TTFB) by a significant factor, depending on your site architecture and end user’s situational connectivity. When Edge Caching is enabled correctly, most customers are able to achieve average TTFBs of < 100ms.
Moovweb’s Edge Caching doesn’t support this use case right now. The Edge Caching layer provides basic HTTP caching and currently doesn’t vary the cache using the HTTP User-Agent header.