Cloudflare Cache Reserve Walkthrough and Demo
Summary
TLDR此视频分享了如何使用Cloudflare的缓存预留功能来提高网站内容的缓存命中率。它首先介绍了Cloudflare CDN的基本工作原理,然后重点讨论了缓存预留的功能和流程。演示了如何在Cloudflare仪表盘中启用该功能,并通过缓存数据到Cloudflare的持久化存储桶来进一步减少服务器负载并降低成本。最后,视频还展示了如何使用Cloudflare的日志和分析功能,更好地了解缓存命中情况和缓存预留的使用情况。
Takeaways
- 💻 Cloudflare CDN 可自动导入当前 DNS 提供商记录,并为用户提供 Cloudflare DNS 服务器使用。
- 🏃 Cloudflare CDN 提供两种加入方式:更改权威 DNS 或部分 CNAME 设置。
- 🗃️ Cloudflare 会根据文件扩展名缓存可缓存内容,当缓存内容过期或手动清除时,会从源服务器重新获取。
- 🌳 缓存分为多层,仅顶层数据中心能从源服务器获取内容。智能分层缓存拓扑可以改善带宽效率和减少源服务器压力。
- 🔄 当发生缓存未命中时,Cloudflare 首先检查持久存储桶中的内容,再从源服务器获取,进一步提升缓存率。
- ⏰ 对于过期或被清除的内容,Cloudflare 会先检查持久存储桶,若内容仍存在则从存储桶获取,降低从源服务器获取频率。
- 🚀 演示中网站部署在第三方云提供商,使用自动流量模拟访问。Cloudflare 控制面板可展示缓存状态和持久存储使用情况。
- 📝 演示中缓存命中率从80%提升至92%,接近100%的优化目标。Cloudflare 提供页面规则微调缓存行为。
- ⌛ 用户可自行设置资源缓存时间,覆盖源服务器设置的 TTL。日志推送功能支持记录来自持久存储的请求数据。
Q & A
什么是Cloudflare CDN?
-Cloudflare CDN(内容分发网络)是一个全球分布的网络基础设施,可以加快网站内容的传输,并提高整体性能。它通过缓存网站内容并将其存储在靠近用户的数据中心,从而减少了从源服务器检索内容的需求,从而降低了延迟并提高了网站的可用性。
如何开始使用Cloudflare CDN?
-要开始使用Cloudflare CDN,您只需在仪表板上单击"添加站点",输入您的域名即可。Cloudflare可以自动从您现有的DNS提供商导入DNS记录。然后,您将获得Cloudflare的名称服务器,可用于更改授权DNS,使用Cloudflare的DNS和CDN。如果您不想更改主DNS,也可以通过部分CNAME设置使用Cloudflare CDN。
请简要解释一下Cloudflare CDN的基本流量流?
-当用户发出HTTP请求时,最接近用户的Cloudflare数据中心将处理该请求。如果请求的URL与可缓存文件扩展名列表匹配,则Cloudflare将从缓存中提供该资源(如果存在)。否则,Cloudflare会尝试从多个网络位置的缓存中获取内容并提供服务。如果内容仍然存在于Cloudflare的缓存中,则会尝试从源重新验证内容。如果资源不在缓存中,Cloudflare会从源请求资源以填充缓存,然后将响应发送给发起请求的客户端。
Cloudflare Cash Reserve是什么?
-Cloudflare Cash Reserve是一种功能,可以进一步提高缓存命中率,将所有可缓存文件自动存储到Cloudflare的持久对象存储桶中。当发生缓存未命中时,Cloudflare将首先在这些存储桶中查找内容,而不是直接从源检索。Cash Reserve充当了终极高级层,有助于减少从源获取内容的需求。
使用Cash Reserve后,流量流会有什么变化?
-使用Cash Reserve后,当客户端向最近的Cloudflare数据中心发出请求时,如果内容在该数据中心和高级层数据中心都没有被缓存,高级层数据中心将先在Cash Reserve中查找内容,而不是立即从源请求。如果内容存在于Cash Reserve,则从那里检索。否则,Cash Reserve将从源请求内容。响应将被缓存在Cash Reserve、高级层和低级层数据中心。下次请求相同内容时,如果在低级层和高级层的缓存都失效,Cloudflare会先在Cash Reserve中查找,如果存在,则从那里提供服务并缓存在其他层。
Cash Reserve使用Cloudflare网络的哪些部分?
-Cash Reserve充当了Cloudflare网络中"终极高级层"。当在低级层和高级层数据中心的缓存都失效时,Cloudflare会先查看Cash Reserve,而不是立即从源请求内容。这有助于最小化从源获取内容的需求,从而减少不必要的出口费用。
如何监控Cash Reserve的使用情况?
-在Cloudflare仪表板中,您可以查看Cash Reserve中当前存储的数据量、一段时间内使用的总存储量,以及总体的Cash Reserve读写操作数。您还可以查看"总体缓存状态",包括由Cloudflare服务的内容和由源服务的内容。使用分析和日志功能,您可以设置日志推送并包括"Cash Reserve 已使用"字段,以获得有关从Cash Reserve服务的请求和相应内容的更多可见性。
如何在Cloudflare中管理缓存行为?
-在Cloudflare仪表板中,您可以"清除缓存"以手动清除缓存(包括Cash Reserve)。您还可以使用"页面规则"来创建更细粒度的缓存行为。在"缓存规则"下,您可以为特定主机名创建规则,以覆盖来自缓存控制标头的TTL设置。这可以在边缘完成,并且为所有资产一次性设置TTL非常方便。
使用Cash Reserve有什么好处?
-使用Cash Reserve可以进一步提高缓存命中率,因为当在Cloudflare网络的其他层发生缓存未命中时,内容将首先从Cash Reserve检索。通过最小化从源请求内容的需求,它有助于减少延迟,减少带宽使用,降低源服务器负载,使网站的运营成本更低。从而提供更好的整体性能。
什么时候会发生缓存未命中?
-有两种情况会导致缓存未命中:1)有意的 - 缓存TTL过期或内容被手动清除;2)无意的 - 由于Cloudflare的LRU(最近最少使用)算法来优化存储空间,不常访问的内容可能会被清除。在这两种情况下,Cash Reserve都可以作为最后一道防线,提高缓存命中率。
Outlines
📚 CloudFlare CDN入门和流量流程
段落1介绍了CloudFlare CDN的基础知识,如何从仪表板开始使用,以及通过CloudFlare CDN的流量流程。当用户请求某个资源时,最近的数据中心会处理该请求。如果资源可缓存,则从缓存中提供。否则,从源服务器获取资源并缓存。CloudFlare使用分层缓存拓扑结构,包括上层和下层数据中心,以控制带宽和连接数。智能分层缓存拓扑是所有计划的默认选项。在流量流中,客户端请求到达最近的下层数据中心。如果在下层未缓存,则会检查上层数据中心。如果上层也未缓存,它会从源服务器请求内容并缓存。接下来当另一客户端请求同一内容时,如果上层已缓存,就不需要再从源服务器获取。另外介绍了缓存过期和云朗缓存清除的原因。
💾 CloudFlare Cash Reserve详解和演示
段落2介绍了CloudFlare Cash Reserve功能以进一步提高缓存命中率。Cash Reserve会自动将所有可缓存文件存储在CloudFlare持久对象存储桶中。在流量流中,当上层数据中心未缓存内容时,会先检查Cash Reserve而不是立即从源请求。如果Cash Reserve有缓存,则返回并缓存在上层和下层数据中心。这一流程大大减少了不必要地从源服务器请求内容。演示部分展示了如何在CloudFlare仪表板中启用Cash Reserve,查看存储使用情况和读写操作数。用于了解在启用Cash Reserve之前和之后的缓存命中率差异。还演示了如何通过缓存规则覆写源服务器的缓存控制头,以及如何记录Cash Reserve使用的日志信息。
Mindmap
Keywords
💡Cloudflare CDN
💡DNS
💡缓存
💡Cache Reserve
💡Tiered Cache
💡缓存命中率
💡缓存控制
💡HTTP请求
💡原点
💡分析和日志
Highlights
云服务商Cloudflare的CDN简介,包括如何开始使用和上手 Cloudflare CDN。
Cloudflare CDN的基本流量流程。
Cloudflare的层级缓存(Tiered Cache)及其智能分层拓扑结构。
何时会发生缓存未命中的情况。
Cloudflare Cash Reserve介绍及其作用。
启用Cash Reserve后的流量流程。
示例网站部署和启用Cash Reserve。
查看Cash Reserve使用情况和数据。
缓存命中率提升情况。
查看缓存详情,包括热门文件类型等。
Purge缓存。
Page规则设置缓存行为。
缓存规则和过期时间覆盖。
外部日志及Cash Reserve使用情况记录。
总结及补充资料链接。
Transcripts
hello my name is humir Ahmed and in this
video I'm going to walk through Cloud
for cash reserve and follow up with demo
I will very briefly discuss some Basics
from cloud for CDN before getting right
into Cash Reserve to provide a better
grasp of how everything fits together
however I'll keep this very minimal so I
can focus on cash Reserve for more
thorough understanding of cloud
vercidian in general and how it works
please see the cloud for CDN reference
architecture in the prior video I did on
cloudflare CDN walkthrough with that
let's get going
first let's talk about how easily you
can get started and onboarded onto
cloudflare CDN
from the dashboard simply click add site
and enter your domain cloud4 can
automatically import your DNS records
from your existing DNS provider and
finally you're given Cloud for name
servers you can use to change your
authoritative DNS so here you're using
cloudford's DNS Azure authoritative DNS
and also onboarded onto cloudflare CDN
now if you don't want to change your
primary or authoritative DNS you can
still use cloudflare CDN by simply doing
a partial cname setup so lots of
flexibility there
so if we look at the very basics of the
traffic flow now first HTTP request is
made closest data center to user handles
the request users HTTP request URL is
matched against the list of cachable
file extensions if the request matches
an extension on the list Cloud first
serves the resource from Cache if
present
second content is fetched from Cache or
origin cloudflare examines its caches in
multiple Network locations for content
and serves it if present if the content
is still in Quad verse cache cloudfare
attempts to revalidate the content with
the origin before serving the response
to the client if the resource is not
present in the cache Cloud Fair requests
the resource from the origin to fill the
cache and the response is then sent to
the client who initiated the request
if cachable content is cached on the
response so cloudflare's cash logic
examines the HTTP response received from
the origin the response is either deemed
cachable and written to disk for use
with the next request for the same
resource or the request is deemed
uncashable
now let's take a look at the traffic
flow with Cloud Fair tiered cache with
smart tiered cache topology enabled as a
reminder tiered cash divides
cloudflare's network of global data
centers into a hierarchy of upper tiers
and lower tiers and in order to control
bandwidth number of connections between
an origin and cloudflare only upper
tiers are permitted to request content
from an origin and are responsible for
Distributing information to the lower
tiers smart tiered cash topology is the
default topology and available for free
for all plans this is also recommended
for most deployments instructing
cloudflare to find the single best upper
tiers for your Origins
benefits here include improved bandwidth
efficiency reduced origin load and
making websites more cost effective to
operate
so when client one sends a request to
the closest data center data center one
here
if the content is not cached the upper
tier data center label data center 3
here is checked if the content is not
cached at the upper tier the upper tier
requests the content from the origin
once their sponsors returned from the
origin the upper tier caches it and
returns a response to the lower tier
which also caches it and returns a
response to the client
now let's say client 2 makes the same
request for the same content to its
closest data center data center too
if the content is not cached to Data
Center too similar to Prior the upper
tier data center is checked however in
this case content was requested prior
via client 1 and the upper tier data
center has the content cached and
Returns the cache content to the lower
tier data center data center 2 which in
turn caches the content and responds
back to the client decreasing latency
saving bandwidth and load on the server
and providing better overall performance
so now that we have a better
understanding of cloud for CDN when does
a cache Miss occur well we have two
scenarios first intentional cash TTL
expired or content purged customers set
cache control time to signify when the
content is out of date and needs to be
revalidated once expired content needs
to be revalidated and may need to be
pulled from the origin if updated
version exists customers can Purge
content manually at any time
second unintentional cloudflare Purge
content due to lru or least recently
used algorithm to optimize storage less
frequently accessed content may be
purged based on lru or how long the
network wants content to remain cached
now this is where Cloud for cash Reserve
can be useful to further increase cash
hit ratio by automatically storing all
cachable files into cloudflare's
persistent object storage buckets
basically cash Reserve acts like an
ultimate upper tier and when there's a
cash Miss cloudflare will first check
these storage buckets before going to
the origin you can see here I've enabled
it and I'll walk through this more in
the demo
so let's look at the traffic flow now
again when the client sends a request to
the lower tier data center if the
content is not cached the upper tier
data center is checked this time however
if the content is not cached at the
upper tier the upper tier checks cash
Reserve instead of requesting straight
from the origin
if the content is not present in cash
Reserve cash Reserve will request it
from the origin once response is
returned from the origin cash Reserve
caches the content while replying to the
upper tier which also caches it and
Returns the response to the lower tier
which also caches it and responds to the
client now next time the same content is
requested if there is a cache Miss at
the lower tier data center the upper
tier data center is checked now if
there's say cache missed at the upper
tier data center let's say expired TTL
or content has been evicted cash Reserve
will be checked and if content exists at
Cash reserve it will be returned and
cached at the upper tier before being
returned and cashed at the lower tier
and returned to the client so you can
see here how cash Reserve acts as the
ultimate upper tier and minimizes the
need to pull from the origin decreasing
unnecessary egress fees
with that let's jump into the demo for
demonstration purposes I deployed a site
here that's basically a large image and
video gallery for uploading and
downloading content
now again for demonstration purposes the
website is actually hosted on a
third-party Cloud I also have automated
traffic running to simulate visitors
accessing the site
so now I'm going to go over and head
over to my cloudflare dashboard and here
you can see I have cash Reserve enabled
and it shows the current amount of data
stored in cash Reserve as well as the
total aggregate storage used over the
specific time period and you also have a
view of total cash Reserve read and
write operations once enabled cash
Reserve will start caching files with a
retention period of 30 days which will
be reset on any hits
customers can also pause using cash
Reserve meaning cloudflare's network
will no longer use cash Reserve to serve
data
here under overview you can see the
overall cash status including content
served by cloudflare and content served
by the origin
you can see the vast majority of
requests are served by cloudflare and if
you scroll down here and hover over the
cast status you can see a
92.96 cash hit ratio really good now
since I just enabled cash reserve a few
days ago if I go up here instead of 24
hours I select previous 30 days
we could see the cash hit ratio was
lower at around 80 percent so cash
Reserve really helped get into that 90
plus ratio getting us closer and closer
to that hundred percent
and scrolling down here you can see more
overall caching details in general like
the most popular content types and what
specific content is the most popular
here on the left you can also Purge the
cache which will also Purge content and
cash reserves you can also create page
rules to get more granular on any
specific caching behavior let's go into
this and take a look in more detail you
can see I created a page rule matching
on all requests that contain this
specific domain name
and I set the cache level to Cache
everything that's cachable but also can
select different cash level including
bypassing cache if desired
so now I'm gonna head over to caching
and look at Cash rules
so under cash rules I can also create a
rule as I did here to override ttls from
Cache control headers
this is done right at the edge and you
can see here if I click into it
all requests to this hostname
I've configured as content eligible for
caching and overridden the origin TTL
setting it to 12 hours with cloudflare
httl it makes it very convenient to set
TTL in one place for all assets
now I'm going to head over to analytics
and logs there
and I'll go under logs you can see I've
set up a log push I'm just going to
click edit here
last thing I want to show here is you
can also log data to external logs and
include the cash Reserve used field to
get more visibility into requests and
respective content being served from
cash Reserve I hope you found this
cloudflare cash Reserve walkthrough in
demo informational and useful for
additional details make sure to check
out the cloudflare cash Reserve product
page
Посмотреть больше похожих видео
2021 Cloudflare: Basic Pages Rules and Cache Levels, Standard and "Cache Everything"
「黑貓」把 M2 Mac mini 用作家用伺服器 | 入門教程 + 體驗感受
Build an AI code generator w/ RAG to write working LangChain
The Unfixable ARM Memory Bug
AI+工作流:解锁ChatGPT全部能力,繁琐工作自动化 | Dify发布Wrokflow实操教程!
Save and persist data with UserDefaults | Todo List #4
5.0 / 5 (0 votes)