Skip to Content
构建可扩展分布式系统:方法与实践
book

构建可扩展分布式系统:方法与实践

by Ian Gorton
May 2024
Intermediate
278 pages
5h 24m
Chinese
China Machine Press
Content preview from 构建可扩展分布式系统:方法与实践
104
6
分布式缓存
缓存存在于应用程序的许多地方。比如,运行应用程序的
CPU
具有高速多级硬件缓存,
可以减少相对较慢的主内存访问。数据库引擎可以利用主内存来缓存数据存储的内容,
这样在许多情况下查询就可以不用访问速度相对较慢的磁盘。
分布式缓存是可扩展系统的重要组成部分。缓存使耗时的查询和计算结果能够在后续请
求中低成本地重用。由于不必为每个请求重建缓存结果,系统的容量增加了,并且可以
扩展来处理更大的工作负载。
在本章中,我将介绍两种类型的缓存。应用缓存依赖业务逻辑,业务逻辑使用分布式缓
存将预计算结果的缓存和访问结合在一起。
Web
缓存充分利用
HTTP
协议中内置的机制
在网络提供的基础设施中缓存结果。只要两种缓存类型有效使用,它们都可以使你的服
务和数据库免受繁重的读取流量负载。
6.1
应用缓存
应用缓存旨在通过将查询和计算的结果存储在内存中来提高请求响应能力,以便为
后续的请求提供服务。举个例子,读者可以发表评论的在线报纸网站,文章一旦发
布,一般就很少会修改。新的评论往往会在文章发表后很快发布,但频率会随着
文章累计发布时间的增长而迅速下降。因此,一篇文章可以在第一次访问时被缓
存,并被所有后续请求重用,直到这篇文章被更新、新评论发布或者再没有人想阅
读它。
一般来说,缓存可以减轻数据库读取流量的负担,因为许多查询都可以直接从缓存中获
取结果。对于构建成本高的对象,例如那些需要跨多个不同数据库查询的对象,缓存还
降低了计算的成本。缓存最终效果是减少了服务和数据库的计算负担,并为更多请求创
造了空间或容量。 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

What Successful Brick-and-Mortar Retailers Get Right

What Successful Brick-and-Mortar Retailers Get Right

Rob Angell
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer
Three Essentials for Agentic AI Security

Three Essentials for Agentic AI Security

Paolo Dal Cin, Daniel Kendzior, Yusof Seedat, Renato Marinho

Publisher Resources

ISBN: 9787111750697