From a66ce64171aa99640e7fb7baa10505477edd3f47 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 27 Nov 2014 23:00:11 -0700 Subject: [PATCH] Added a configuration option to set a default lifetime on cache saves --- system/config/system.yaml | 1 + system/src/Grav/Common/Cache.php | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/system/config/system.yaml b/system/config/system.yaml index 88b979199..a075032a0 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -27,6 +27,7 @@ cache: method: file # Method to check for updates in pages: file|folder|none driver: auto # One of: auto|file|apc|xcache|memcache|wincache prefix: 'g' # Cache prefix string (prevents cache conflicts) + lifetime: 86400 # Lifetime of cached data in seconds (0 = infinite) twig: cache: true # Set to true to enable twig caching diff --git a/system/src/Grav/Common/Cache.php b/system/src/Grav/Common/Cache.php index aa6fe940b..9da3974a8 100644 --- a/system/src/Grav/Common/Cache.php +++ b/system/src/Grav/Common/Cache.php @@ -154,6 +154,10 @@ class Cache extends Getters public function save($id, $data, $lifetime = null) { if ($this->enabled) { + + if ($lifetime == null) { + $lifetime = $this->config->get('system.cache.lifetime') ?: null; + } $this->driver->save($id, $data, $lifetime); } }