Skip to player
Skip to main content
Skip to footer
Search
Connect
Watch fullscreen
Like
Comments
Bookmark
Share
Add to Playlist
Report
How to create a cache for database requests in Django REST Framework
InterTuts
Follow
9/2/2024
django.core.cache is Django's built-in caching framework, which provides a standardized way to cache data within a Django application.
This video shows an easy implementation of django.core.cache with database request.
Category
🦄
Creativity
Transcript
Display full video transcript
00:00
Every time a user accesses this page, posts are requested from the server.
00:12
To load them faster, I'm using cache.
00:17
In this video, I'll explain how.
00:21
In the backend, I have created for Django a file called cache.
00:33
In this file, I have created a CacheManager class to manage the cache for posts.
00:47
When I create an instance for this class CacheManager,
00:57
I'm providing the user ID and the page number to create a unique cache for each request.
01:12
Because I need to save in cache only the user posts and only posts for a page.
01:27
I'm creating a unique cache key based on user ID and page number.
01:39
Next, I'm requesting the posts from the database.
01:47
If posts exist, I'm saving them in a cache using this code.
01:58
When the user accesses the page where are displayed the posts,
02:12
I'm verifying first if the cache exists for that user and the page number.
02:23
If cache exists, this means I will return this cache.
02:33
In this way, I will avoid to make all these verifications and request the data from the database.
02:53
In this way, I will avoid to make all these verifications and request the data from the database.
03:03
In this way, I will avoid to make all these verifications and request the data from the database.
Recommended
2:58
|
Up next
How to create a custom management command in Django
InterTuts
11/17/2024
5:24
How to create cache for dynamic posts displayed by page using Django
InterTuts
9/3/2024
4:27
Vue.js & Django Authentication: token login with Django REST Framework
InterTuts
7/4/2024
4:01
How to delete data from database using Django REST Framework
InterTuts
10/19/2024
6:20
Vue.js & Django Authentication: password reset code guide
InterTuts
7/9/2024
5:59
How to test user update in Django Rest Framework
InterTuts
6/25/2024
2:40
Vue.js & Django Authentication: create a new app
InterTuts
7/2/2024
4:56
Broomhilda meeting Django scene (Django Unchained)
Django Unchained
9/6/2015
6:00
How to join multiple tables in Django using prefetch_related tool
InterTuts
11/5/2024
2:16
002 Software
rubpocoyo
4/9/2018
1:46
Learn Django 4.0 - Build Dynamic Web Apps
Prime Inspire
5/24/2023
1:02
Django
Télé 7 Jours
2/13/2023
3:43
Vue.js & Django Social Scheduler: how to publish a post on a Facebook Page
InterTuts
10/31/2024
2:28
Pagination in React & Next JS
InterTuts
12/20/2024
1:47
React & Node.js Social Chat: unsubscribe Facebook Pages from application's webhook
InterTuts
12/18/2024
1:22
How to use notifications alerts in React & Next JS
InterTuts
12/18/2024
3:30
React & Node.js Social Chat: how to connect Facebook Pages to receive direct messages
InterTuts
12/18/2024
1:56
How to convert a string to MongoDB ObjectId in Node.js
InterTuts
12/17/2024
2:05
How to bulk insert or update data in MongoDb with Mongoose
InterTuts
12/16/2024
1:41
How to retrieve URL's query parameters in Next.js(CSR)
InterTuts
12/15/2024
3:27
How to handle dynamic route parameters in Express.js
InterTuts
12/14/2024
1:42
How to retrieve and pass dynamic route segment between components in Next.js & React
InterTuts
12/14/2024
2:00
How to create vertical tabs in Chakra UI
InterTuts
12/14/2024
1:53
How to create a modal in Chakra UI & React
InterTuts
12/13/2024
0:49
React & Node.js Social Chat: Introduction
InterTuts
12/11/2024