Answer the question
In order to leave comments, you need to log in
How to long-term "cache" results in Postgres?
Postgres 9.5
There is a heavy query. But the data in it does not have to be absolutely fresh.
I know about Materialized view, but apparently, this is not what I need.
I'd like to run the query even if it takes a few seconds, and then store the results somewhere where they're available until I decide to update them.
This is almost a Materialized view, but the fact is that there are variables there, and it makes no sense to do MW for with all the variations of these variables. A variable is, say, a combination of id's of two different users. Doing MW for all variations of all existing users is pointless. But saving the results on the first call and showing them before the expiration of some trigger or deadline is what you need. Is there some simple solution without having to write a bunch of trigger functions?
Answer the question
In order to leave comments, you need to log in
SELECT ... FROM cache_table
; UPDATE cache_table SET ... FROM SELECT ...
(here is your heavy request);DELETE FROM cache_table WHETE ...
.Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question