# [[Cache]]
![[Cache.svg]]
A cache is a [[Data storage]] component that saves information for future use.
## Types of cache
Caches can exist at many levels and for different types of information.
### Hardware-level caches
L1/L2/L3 caches can be built into the [[CPU]] and store recently accessed instructions or data to improve performance.
### System/OS-level caches
[[Disk cache|Disk caches]] keep frequently accessed information in [[RAM]] so that it can be shown quickly without needing to be retrieved again.
[[Page cache|Page caches]] in [[Linux]] stores system pages in memory to improve read/write performance.
### Web/application-level caches
[[Memcache|Memcaches]], or memory caches, store information like user sessions, query results, or API responses in RAM.
Local application caches store information about the application's usage.
### Client-side caches
[[localStorage]] is a web browser's local cache. Resources are stored locally to avoid needing to make requests over the internet to retrieve them.
[[Service Worker Cache|Service Worker Caches]] in [[Progressive Web Apps]] cache resources so that they can be accessed locally.
A cache, when properly implemented, affects both back-end and front-end performance of an application as well as end user experience.
The goal of caching is to reduce the number of network requests and latency between an application server and the client.
### Network caches
A [[Content Delivery Network|CDN]] is a type of remote cache that stores information in strategic locations around the world so that the information can be served to users that are geographically closer to those caches.
[[Reverse Proxy|Reverse Proxy Caches]] (like [[Nginx]] or [[Varnish]]) sit between a client and a server, catch HTTP responses from backend servers, and then process them in some way or forward them.
### Database-level caches
Caches are often used in databases to store [[query|query results]] so that they can be served faster without performing lookups later. This can occur on multiple components.
## [[Cache Headers]]
Applications typically determine when and which resources are cached by users' browsers by sending special headers in an HTTP response. Most browsers follow standard HTTP specification and implement caching by default, using headers.
%%
# Excalidraw Data
## Text Elements
## Drawing
```json
{
"type": "excalidraw",
"version": 2,
"source": "https://github.com/zsviczian/obsidian-excalidraw-plugin/releases/tag/2.1.4",
"elements": [
{
"id": "4y8R7iOA",
"type": "text",
"x": 118.49495565891266,
"y": -333.44393157958984,
"width": 3.8599853515625,
"height": 24,
"angle": 0,
"strokeColor": "#1e1e1e",
"backgroundColor": "transparent",
"fillStyle": "solid",
"strokeWidth": 2,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"groupIds": [],
"frameId": null,
"roundness": null,
"seed": 967149026,
"version": 2,
"versionNonce": 939059582,
"isDeleted": true,
"boundElements": null,
"updated": 1713723615080,
"link": null,
"locked": false,
"text": "",
"rawText": "",
"fontSize": 20,
"fontFamily": 4,
"textAlign": "left",
"verticalAlign": "top",
"containerId": null,
"originalText": "",
"lineHeight": 1.2
}
],
"appState": {
"theme": "dark",
"viewBackgroundColor": "#ffffff",
"currentItemStrokeColor": "#1e1e1e",
"currentItemBackgroundColor": "transparent",
"currentItemFillStyle": "solid",
"currentItemStrokeWidth": 2,
"currentItemStrokeStyle": "solid",
"currentItemRoughness": 1,
"currentItemOpacity": 100,
"currentItemFontFamily": 4,
"currentItemFontSize": 20,
"currentItemTextAlign": "left",
"currentItemStartArrowhead": null,
"currentItemEndArrowhead": "arrow",
"scrollX": 583.2388916015625,
"scrollY": 573.6323852539062,
"zoom": {
"value": 1
},
"currentItemRoundness": "round",
"gridSize": null,
"gridColor": {
"Bold": "#C9C9C9FF",
"Regular": "#EDEDEDFF"
},
"currentStrokeOptions": null,
"previousGridSize": null,
"frameRendering": {
"enabled": true,
"clip": true,
"name": true,
"outline": true
}
},
"files": {}
}
```
%%