Created
June 14, 2011 05:44
-
-
Save sevein/1024392 to your computer and use it in GitHub Desktop.
Use sfFileCache to cache Qubit settings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: lib/SiteSettingsFilter.class.php | |
=================================================================== | |
--- lib/SiteSettingsFilter.class.php (revision 9157) | |
+++ lib/SiteSettingsFilter.class.php (working copy) | |
@@ -20,30 +20,29 @@ | |
class siteSettingsFilter extends sfFilter | |
{ | |
/* | |
- * execute this filter on every request in case some params have changed since the last page load | |
+ * Execute this filter on every request in case some params have changed since the last page load | |
*/ | |
public function execute($filterChain) | |
{ | |
- // create a function cache object for the QubitSettings method call | |
- //$fileCache = new sfFileCache(array('cache_dir' => sfConfig::get('sf_app_cache_dir').'/settings')); | |
+ // Create a function cache object for the QubitSettings method call | |
+ $cache = new sfFileCache(array('cache_dir' => sfConfig::get('sf_app_cache_dir').'/settings')); | |
- // invalidate cache when user switches culture | |
- // FIXME: there must be a smarter way to detect this accurately; user culture is set very early after routing | |
- if ($this->context->request->sf_culture) | |
+ // Get settings (from cache if exists) | |
+ if ($cache->has('settings')) | |
{ | |
- //$fileCache->clean(); | |
+ $settings = unserialize($cache->get('settings')); | |
} | |
+ else | |
+ { | |
+ $settings = QubitSetting::getSettingsArray(); | |
- //$functionCache = new sfFunctionCache($fileCache); | |
- | |
- // get settings (from cache if it exists) | |
- //$settings = $functionCache->call(array(new QubitSetting, 'getSettingsArray')); | |
- $settings = QubitSetting::getSettingsArray(); | |
+ $cache->set('settings', serialize($settings)); | |
+ } | |
- // overwrite/populate settings into sfConfig object | |
+ // Overwrite/populate settings into sfConfig object | |
sfConfig::add($settings); | |
- // execute next filter | |
+ // Execute next filter | |
$filterChain->execute(); | |
} | |
} | |
Index: apps/qubit/modules/settings/actions/listAction.class.php | |
=================================================================== | |
--- apps/qubit/modules/settings/actions/listAction.class.php (revision 9157) | |
+++ apps/qubit/modules/settings/actions/listAction.class.php (working copy) | |
@@ -69,6 +69,10 @@ | |
// Handle POST data (form submit) | |
if ($request->isMethod('post')) | |
{ | |
+ // Clean cache | |
+ $cache = new sfFileCache(array('cache_dir' => sfConfig::get('sf_app_cache_dir').'/settings')); | |
+ $cache->clean(); | |
+ | |
// Global settings form submission | |
if (null !== $request->global_settings) | |
{ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment