Skip to content

Commit 1945024

Browse files
committed
Add Caching at the database query level vs obj level sections
1 parent e161b29 commit 1945024

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,3 +1252,24 @@ There are multiple levels you can cache that fall into two general categories: *
12521252
* Fully-rendered HTML
12531253

12541254
Generaly, you should try to avoid file-based caching, as it makes cloning and auto-scaling more difficult.
1255+
1256+
### Caching at the database query level
1257+
1258+
Whenever you query the database, hash the query as a key and store the result to the cache. This approach suffers from expiration issues:
1259+
1260+
* Hard to delete a cached result with complex queries
1261+
* If one piece of data changes such as a table cell, you need to delete all cached queries that might include the changed cell
1262+
1263+
### Caching at the object level
1264+
1265+
See your data as an object, similar to what you do with your application code. Have your application assemble the dataset from the database into a class instance or a data structure(s):
1266+
1267+
* Remove the object from cache if its underlying data has changed
1268+
* Allows for asynchronous processing: workers assemble objects by consuming the latest cached object
1269+
1270+
Suggestions of what to cache:
1271+
1272+
* User sessions
1273+
* Fully rendered web pages
1274+
* Activity streams
1275+
* User graph data

0 commit comments

Comments
 (0)