Mirac7
Mirac7

Reputation: 1646

Single record of model in database

My django app needs to display data on my homepage which it collected from third party. Requesting the information and waiting for response takes about a second, which is too long processing time for a homepage. The data which my app receives doesn't change often, so there is no reason to fetch that data every time homepage is being rendered. Instead, I want to retain the data and have my app make a request only if the last "refresh" has been done more than an hour ago.

Since using global variables in django is apparently a no-no, I'd need to make a database model which will at all times hold a single record. This feels wrong. Is making a one-record table really a way to go here?

Upvotes: 0

Views: 99

Answers (1)

OrenD
OrenD

Reputation: 1741

Instead of creating a model to cache the remote site's response, you can use Django's caching framework. More specifically, you can cache a specific view and set a timeout for the cached view. See this documentation page for more details on how to do that.

Upvotes: 3

Related Questions