Shri
Shri

Reputation: 731

Django: Database caching to store web service result

I have a method to load all ideas from database. There are few comments on each idea.

I have store users id who commented on ideas, in respective table.

I have a web service which contains all the data related to user id

When i load a page, it took time to fetch information for all users using web service.

I want to use databse caching to store that web service response and use that later on.

How to achieve this, to reduce page load timing?

when should i store that web service response in cache table?

Upvotes: 0

Views: 92

Answers (1)

sidp
sidp

Reputation: 147

The Django documentation on the cache framework is pretty easy to follow and will show you exactly how to set up a database cache for pages and other things in your views, including for how long you'd like the cache to exist, TIMEOUT, as well as other arguments a cache can take.

Another way to speed up accessing your DB information is to take advantage of CONN_MAX_AGE for your database in your settings.py, who's time can be dependent on how often the database needs to be accessed or how much traffic the site gets (as an example). This is basically letting your DB connection know how long to stay open, and can be found in the settings documentation.

You can store information in a cache when something on the site occurs (such as a new comment) or when that particular request is made for a particular page. It can be entirely up to the needs of your project.

Upvotes: 1

Related Questions