[Fixed]-Django: Database caching to store web service result

1👍

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.

👤sidp

Leave a comment