You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/technical-overview/caching.md
+6-28Lines changed: 6 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,48 +4,26 @@ sidebar_position: 8
4
4
5
5
# Caching
6
6
7
-
:::important
8
-
9
-
We’re currently making rapid changes to the product so our docs may be out of date. If you need help, please email [yo@forem.com](mailto:yo@forem.com).
10
-
11
-
:::
12
7
13
8
_This has been adapted from [The Three Caches of Forem // Take on Rules](https://takeonrules.com/2022/03/29/the-three-caches-of-forem/)_
14
9
15
10
16
11
In the Forem code base, we make extensive use of various caching strategies. And as with any cache, we always run the risk of not invalidating the right caches.
17
12
18
-
The three caching strategies are:
19
-
20
-
- Edge Caching
21
-
- Rails Caching
22
-
- Database Caching
13
+
You can read more about our response caching strategies here:
14
+
https://dev.to/devteam/caching-at-dev-11el
23
15
24
-
At a high level, we leverage caches to improve performance. Let’s delve into each strategy. But before we do, let’s introduce a few concepts.
16
+
We also dive more into Rails Caching which touches on (Fragment Caching)and Database Caching below.
25
17
26
-
## Response Documents and Fragments
18
+
At a high level, we leverage caches to improve performance. Let’s start of by introducing by detailing what a Response Document and Fragment is.
27
19
28
20
The <dfn>response document</dfn> is a single file sent from the server in response to a request.
29
21
30
22
Remember that what you see rendered in your browser is almost always from the combination of many _response documents_ sent from the server: <abbrtitle="Hypertext Markup Language">HTML</abbr> documents, Javascript files, <abbrtitle="Cascading Stylesheet">CSS</abbr> files, and <abbrtitle="XMLHttpRequest">XHR</abbr> that modify the <abbrtitle="Document Object Model">DOM</abbr>.
31
23
32
24
To build a single _response document_, the server often assembles multiple fragments to form that singular document. In Ruby on Rails this is done with like layouts, views, and partial views.
33
25
34
-
## Back to Listing the Caching Strategies
35
-
36
-
Let’s now work from the broader caching strategies to the more narrow ones.
37
-
38
-
### Edge Caching
39
-
40
-
Edge caching is about trying to put as many of the _response documents_ as close to the client as possible to reduce latency on content delivery.
41
-
42
-
At Forem, we enable the usage of either Fastly or Nginx. When we bust the edge cache, we are evicting specific _response documents_.
43
-
44
-
The next time someone requests that _response document_ the server will reassemble it (from the various constituent parts).
45
-
46
-
You can see [our Edge Busting strategy here](https://github.com/forem/forem/blob/main/app/services/edge_cache/bust.rb).
47
-
48
-
### Rails Caching
26
+
## Rails Caching
49
27
50
28
We use the Rails cache to store all kinds of things, mostly fragments that we use to build the response document.
51
29
@@ -63,7 +41,7 @@ When an admin makes a site wide change, that prompts to use a new key; so long a
63
41
64
42
You can learn more about [Caching with Rails](https://guides.rubyonrails.org/caching_with_rails.html) over at the Rails Guides.
65
43
66
-
###Database Caching
44
+
## Database Caching
67
45
68
46
The last is database caching. We cache an article’s tag list, user, and organization information (if applicable). These are cached as fields on the articles table. The purpose of these cached attributes is performance. Where possible, we prefer to minimize joins for queries that we frequently perform (e.g. get me a list of articles being a very common query for a Forem).
0 commit comments