<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Peakhour.IO - Caching</title><link href="https://www.peakhour.io/" rel="alternate"></link><link href="https://www.peakhour.io/feeds/caching.atom.xml" rel="self"></link><id>https://www.peakhour.io/</id><updated>2022-06-10T13:00:00+10:00</updated><entry><title>Origin shield</title><link href="https://www.peakhour.io/blog/cdn-origin-shield/" rel="alternate"></link><published>2022-06-10T13:00:00+10:00</published><updated>2022-06-10T13:00:00+10:00</updated><author><name>AC</name></author><id>tag:www.peakhour.io,2022-06-10:/blog/cdn-origin-shield/</id><summary type="html">&lt;p&gt;Origin shield is a CDN must have feature that increases your Cache Hit Rate by consolidating requests from POPs.&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;a href="/learning/cdn/"&gt;CDN&lt;/a&gt; providers often promote the size of their network, and how many Points of Presence (POPs) they have. Higher
capacity, more resilient networks are useful from a security point of view (think DDoS attacks), but more POPs can also
work against what the CDN was designed to do: take load off an origin and improve performance for end users.&lt;/p&gt;
&lt;h2&gt;The POP Problem&lt;/h2&gt;
&lt;p&gt;Modern CDNs are what's called 'Pull' CDNs. That means the CDN won't store content/resources until a user requests it.
The first time a user requests a resource, it goes to the CDN POP, checks its local cache, gets a miss, and then passes the request
through to origin. As the resource is returned, the CDN stores a copy for the next time someone wants it. If your CDN has
100 POPs, then this process has to be repeated 100 times to fully 'warm' the CDN for that specific resource. That's 100 requests to origin.
The more POPs your CDN has, the more likely you are to get a miss and hit the origin.&lt;/p&gt;
&lt;p&gt;&lt;img src="/static/images/blog/origin-shield-without.png" class="img-responsive"&gt;&lt;/p&gt;
&lt;p&gt;When the caches at POPs are fully populated, the effect on your application can be minimal. During a cache MISS
event, typically either due to resource expiration or a manual purge, many requests can be sent to the origin server
concurrently while the individual POPs rebuild their caches. The more POPs, the longer the process takes.&lt;/p&gt;
&lt;p&gt;This can be a problem, especially when caching dynamic pages that need to be server side rendered, large resources, or transformed
resources. For example, take a busy ecommerce store running Magento during a sale, Magento will purge content when sales
are made, forcing the cache to rebuild each time. During a busy period it can reduce your cache hit rate
and degrade site performance.&lt;/p&gt;
&lt;h2&gt;Enter Origin Shield&lt;/h2&gt;
&lt;p&gt;CDN Origin Shield is a feature that lets you nominate the CDN Point of Presence closest to your server as a shield. All
requests that hit other POPs and receive a cache miss will then go to the nominated shield before hitting the origin. The
shield becomes a 'super cache' and can reduce the amount of requests to your origin in a cache miss.&lt;/p&gt;
&lt;p&gt;&lt;img src="/static/images/blog/origin-shield-with.png" class="img-responsive"&gt;&lt;/p&gt;
&lt;p&gt;Peakhour.IO implements origin shield as a simple dropdown on an origin pool where you can select the geographic location
that should be used as a shield. Requests to your origin are now routed through this geographic location
before reaching your origin in a cache miss scenario.&lt;/p&gt;
&lt;p&gt;Clients who use multiple geographic origins can also benefit from Origin shield. Peakhour.IO allows the specification
of an origin shield per origin. For geographic load balancing, you will need to contact support
for setup.&lt;/p&gt;
&lt;h2&gt;Seeing is believing&lt;/h2&gt;
&lt;p&gt;The Peakhour.IO summary now includes your edge CHR, your shield CHR and your overall CHR so that you can see the effect
in action.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Some of our clients have seen typical increases of 10-20% of their overall Cache Hit Rate, and greater than 40% when
  specifically looking at often flushed dynamic content.&lt;/li&gt;
&lt;li&gt;Quicker cache convergence&lt;/li&gt;
&lt;li&gt;Fewer hits to origin&lt;/li&gt;
&lt;li&gt;Better end-user experience&lt;/li&gt;
&lt;li&gt;Higher conversions&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Final Thoughts&lt;/h2&gt;
&lt;p&gt;Origin Shield is an important feature for certain types of site, or when you're looking to maximise your cache hit rate.
CMSs that offer built in full page caching, like Magento and
Drupal, flush content often, and are susceptible to performance degradation as load increases. Minimising hits to the origin
in these cases is vital.&lt;/p&gt;
&lt;p&gt;If you are interested in getting more out of your CDN, need a bespoke CDN solution, or need a provider that
offers performance, optimisation and security services, reach out to discuss the right setup.&lt;/p&gt;
&lt;p&gt;Origin shield with &lt;a href="/blog/request-collapsing/"&gt;request collapsing&lt;/a&gt; helps minimise
origin hits, improve CHR and maintain user experience for your web application.&lt;/p&gt;</content><category term="Caching"></category><category term="CDN"></category><category term="DDoS"></category><category term="Residential Proxies"></category><category term="DNS"></category></entry><entry><title>CDN Cache Keys</title><link href="https://www.peakhour.io/blog/cdn-cache-keys/" rel="alternate"></link><published>2022-05-16T13:00:00+10:00</published><updated>2022-05-16T13:00:00+10:00</updated><author><name>AC</name></author><id>tag:www.peakhour.io,2022-05-16:/blog/cdn-cache-keys/</id><summary type="html">&lt;p&gt;Cache keys allows the segmenting of the Peakhour.IO cache by elements of both the request and response, enabling effective and flexible caching of content.&lt;/p&gt;</summary><content type="html">&lt;p&gt;Content Delivery Networks (CDNs) are common on business websites. CDNs speed up websites by storing website content
and assets in caches on servers spread around the world. These caches are typically key/value stores. For example,
let's say we are requesting an image found at:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;https://www.example.com/someimage.jpg
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Depending on how the &lt;a href="/learning/cdn/"&gt;CDN&lt;/a&gt; works internally, it may use &lt;strong&gt;/someimage.jpg&lt;/strong&gt; (the key) to retrieve the image (the value)
from its cache. Most CDNs are fairly rigid in what they use as keys, complicated to configure (eg requiring programming
skills), or charge more for flexibility.&lt;/p&gt;
&lt;p&gt;The Peakhour.io CDN cache keeps configuration flexible while still supporting fine-grained control of caching
behaviour for your application.&lt;/p&gt;
&lt;p&gt;The Peakhour.IO cache key consists of a primary key, sub key, and secondary key. Both the primary and secondary key must
match to constitute a cache hit.&lt;/p&gt;
&lt;h2&gt;Primary key&lt;/h2&gt;
&lt;p&gt;The primary key is the key from the client request that uniquely identifies a resource. It consists of the
scheme, host, path and query string from the request. Within our cache, the primary key may be augmented from other
elements of the request, such as the presence of a particular header, or a header value such as a cookie value. At
Peakhour.IO, we call these augmented keys &lt;a href="/docs/reference/rules/vconf-set/#cache-subkey-vars"&gt;cache subkey vars&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src="/static/images/blog/url-cache-key-composition.png" class="img-responsive"&gt;&lt;/p&gt;
&lt;p&gt;The following options can further manipulate the primary key by specifying how the query string is handled. These
options include &lt;a href="/docs/reference/rules/vconf-set/#cdn-query-mode"&gt;ignore query string&lt;/a&gt; (useful for defeating cache-busting techniques)
or &lt;a href="/docs/reference/rules/vconf-set/#cdn-remove-query-args"&gt;stripping certain tags&lt;/a&gt; (commonly UTM tags).&lt;/p&gt;
&lt;h2&gt;Secondary key&lt;/h2&gt;
&lt;p&gt;The secondary key describes parts of the request message that influenced the content of the response from the origin.
This information is stored in the secondary key and the following headers are used:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Vary&lt;/li&gt;
&lt;li&gt;Content-Encoding&lt;/li&gt;
&lt;li&gt;User-Agent: (browser/mobile)&lt;/li&gt;
&lt;li&gt;Accept-Language&lt;/li&gt;
&lt;li&gt;Variant-06&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Servers are commonly misconfigured and can send back headers that don't match the behaviour of the content.
For example, it is very common for a server to send back a Vary header with &lt;em&gt;Vary: user-agent&lt;/em&gt;. When you check the behaviour
by sending different user agents, though, the content doesn't actually change. This can cause unnecessary cache fragmentation and lower hit rates. Peakhour allows
you to override/ignore origin behaviour to correct this.&lt;/p&gt;
&lt;p&gt;If you prefer a visual view, the diagram below shows all the elements of a request/response that could make up a cache key.&lt;/p&gt;
&lt;p&gt;&lt;img src="/static/images/blog/cache-keys.png" class="img-responsive"&gt;&lt;/p&gt;
&lt;p&gt;For more flexibility, Peakhour.io can use specific Cookie values in the secondary key. This is useful for Content Management
Systems like Magento, which set a special cookie, &lt;em&gt;X-Magento-Vary&lt;/em&gt;, to enable special caching behaviour that wouldn't normally
be achievable; for example, whether the user is logged in, is part of a special group, or has chosen a different currency.&lt;/p&gt;
&lt;h2&gt;How can I see my keys?&lt;/h2&gt;
&lt;p&gt;Cache keys are generated on the fly based on the client's request and the origin's response. To see a cache key,
enable Debug headers in the Peakhour.IO dashboard. As an example, for the given request/response pair:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nf"&gt;GET&lt;/span&gt; &lt;span class="nn"&gt;/&lt;/span&gt; &lt;span class="kr"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt;
&lt;span class="na"&gt;Accept-Encoding&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="l"&gt;gzip, deflate, br&lt;/span&gt;

HTTP/1.1 200
Vary: accept-encoding
content-encoding: br
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Peakhour.IO would generate the following cache-status header:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nt"&gt;cache-status&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;peakhour&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;io&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;fwd&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nt"&gt;uri-miss&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;https://example.com/what-is-new.html&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;secondary-key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;encoding::br&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;stored&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;ttl&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nt"&gt;31536000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Here, the key is the scheme://host/path and the secondary-key is the encoding served by the origin.&lt;/p&gt;
&lt;h2&gt;What's in it for me?&lt;/h2&gt;
&lt;p&gt;By understanding cache keys and how they are constructed, a web application can tailor its responses to better utilise
a cache. The configuration options give you direct control for fine-tuning cache-key handling, improving user experience
and cache hit rates.&lt;/p&gt;</content><category term="Caching"></category><category term="CDN"></category><category term="Caching"></category><category term="Drupal"></category><category term="Web Performance"></category></entry><entry><title>Request collapsing</title><link href="https://www.peakhour.io/blog/request-collapsing/" rel="alternate"></link><published>2022-05-16T11:00:00+10:00</published><updated>2022-05-16T11:00:00+10:00</updated><author><name>AC</name></author><id>tag:www.peakhour.io,2022-05-16:/blog/request-collapsing/</id><summary type="html">&lt;p&gt;Request collapsing - saving your origin by reducing concurrent requests and re-using responses for resources.&lt;/p&gt;</summary><content type="html">&lt;p&gt;Request collapsing protects busy origin servers that serve changing content. On a high traffic site, a cache miss
after content expires can amplify one expired resource into many simultaneous origin requests. This behaviour is commonly
called a cache stampede or dog-piling.&lt;/p&gt;
&lt;p&gt;When request collapsing is enabled, only a single request is sent to an origin server for a given resource, then the
resulting body is used to satisfy pending requests.&lt;/p&gt;
&lt;p&gt;This can stop a popular cached resource from causing a flood of requests to an origin server when it expires.
On high traffic sites, enabling the feature for the right resources can smooth request volume and traffic to origin servers.&lt;/p&gt;
&lt;p&gt;&lt;img src="/static/images/blog/request-collapsing.png" class="img-responsive"&gt;&lt;/p&gt;
&lt;h1&gt;How it works&lt;/h1&gt;
&lt;p&gt;Request collapsing is implemented internally using &lt;a href="/blog/cache-keys/"&gt;cache keys&lt;/a&gt; and queues.
Cache keys are used as keys to a map, with client requests tracked using a queue. Secondary response keys
are then used to match waiting client requests to origin responses. Matching requests can then be fulfilled using the
same response.&lt;/p&gt;
&lt;p&gt;Failed requests are retried in the same manner.&lt;/p&gt;
&lt;p&gt;If a response to an active request is marked as private with &lt;code&gt;Cache-Control: private&lt;/code&gt; or &lt;code&gt;Set-Cookie&lt;/code&gt;, then all queued
and future matching requests will go directly to the origin without trying to match them.&lt;/p&gt;
&lt;p&gt;This implementation allows Peakhour to serialise requests to an origin, so it's important to enable the feature only on
resources that you know will be cacheable, either through cache-control headers or Peakhour configuration.&lt;/p&gt;
&lt;h1&gt;How do you know its working?&lt;/h1&gt;
&lt;p&gt;Request collapsing can be verified with Debug enabled and the cache-status header in the response. A collapsed request
looks like the example below, with 'collapsed' at the end.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="nt"&gt;cache-status&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;peakhour&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;io&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;fwd&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nt"&gt;uri-miss&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;https://website.com/home-eco.jpg&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;ttl&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nt"&gt;86400&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;collapsed&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h1&gt;How its used in practice?&lt;/h1&gt;
&lt;h2&gt;Image optimisation&lt;/h2&gt;
&lt;p&gt;Peakhour.IO uses request collapsing internally for image transforms. The feature ensures we only transform a single image
when a resource expires on the edge, reducing latency sensitive image transformation work, client transform costs and
avoidable delays for end users.&lt;/p&gt;
&lt;h2&gt;Dynamic page caching&lt;/h2&gt;
&lt;p&gt;Request collapsing is a good fit when enabling caching of expensive dynamically written pages. Peakhour.IO
can cache server heavy WordPress, Magento, PrestaShop, Drupal and other platforms via our caching plugin. The plugin
keeps the CDN in sync by notifying us when content changes.&lt;/p&gt;
&lt;p&gt;Content still needs to change during busy periods such as sales or item purchases. During these periods
servers can be overwhelmed when pages incur a cache miss. Request collapsing can help smooth out this traffic and maintain
response times for users.&lt;/p&gt;</content><category term="Caching"></category><category term="Caching"></category><category term="CDN"></category><category term="Rate Limiting"></category><category term="Drupal"></category></entry></feed>