Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting expiration time when caching view

I want to cache the result from a view in Oracle. My view is declared as:

CREATE VIEW SOME_VIEW AS
SELECT
    /*+ RESULT_CACHE */
    u.name
    c.info
FROM
    Users u
    LEFT OUT JOIN Contacts c ON c.user_id = u.id

Now I want to explicitly set the cache expiration time of the for this view. If I have understood it right, the expiration is applied to the cache globaly.

Is it possible to set the expiration time per query?

like image 650
chaliasos Avatar asked Jan 03 '17 08:01

chaliasos


People also ask

What is cache expiration time?

When the Expires date is equal to the Date header value, the response is considered to be expired. When a response has an Expires header field with a date/time that is in the future, then that response is considered "cacheable". Servers should not set an Expires date that is more than one year in the future.

What is default TTL in CloudFront?

Minimum TTL: 1 second. Maximum TTL: 31,536,000 seconds (365 days). Default TTL: 86,400 seconds (24 hours).


1 Answers

Result Set Caching stashes the result set of a query in-memory. Any query which returns this result set (or a subset of it) hits the cache instead of the database. The lifespan of the cache is from the first time the source query is executed until the underlying tables are changed through DML. This makes the /*+ RESULT_CACHE */ hint ideal for queries which are expensive to execute (or executed very often) and which select from tables whose data doesn't change very often.

Consequently there isn't any mechanism for us to invalidate the result set cache: the database manages it for us invisibly. Nevertheless, if you really wanted to invalidate the cache periodically (your database is performing too well or something) maybe you could schedule a job to execute a meaningless update on one of the tables the view relies on:

update Contacts c
set c.user_id = c.user_id + 0
like image 100
APC Avatar answered Sep 28 '22 08:09

APC