1 <?php
2 /**
3 * @package FrameworkOnFramework
4 * @subpackage utils
5 * @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
6 * @license GNU General Public License version 2 or later; see LICENSE.txt
7 */
8
9 defined('FOF_INCLUDED') or die;
10
11 /**
12 * A utility class to help you quickly clean the Joomla! cache
13 */
14 class FOFUtilsCacheCleaner
15 {
16 /**
17 * Clears the com_modules and com_plugins cache. You need to call this whenever you alter the publish state or
18 * parameters of a module or plugin from your code.
19 *
20 * @return void
21 */
22 public static function clearPluginsAndModulesCache()
23 {
24 self::clearPluginsCache();
25 self::clearModulesCache();
26 }
27
28 /**
29 * Clears the com_plugins cache. You need to call this whenever you alter the publish state or parameters of a
30 * plugin from your code.
31 *
32 * @return void
33 */
34 public static function clearPluginsCache()
35 {
36 self::clearCacheGroups(array('com_plugins'), array(0,1));
37 }
38
39 /**
40 * Clears the com_modules cache. You need to call this whenever you alter the publish state or parameters of a
41 * module from your code.
42 *
43 * @return void
44 */
45 public static function clearModulesCache()
46 {
47 self::clearCacheGroups(array('com_modules'), array(0,1));
48 }
49
50 /**
51 * Clears the specified cache groups.
52 *
53 * @param array $clearGroups Which cache groups to clear. Usually this is com_yourcomponent to clear your
54 * component's cache.
55 * @param array $cacheClients Which cache clients to clear. 0 is the back-end, 1 is the front-end. If you do not
56 * specify anything, both cache clients will be cleared.
57 *
58 * @return void
59 */
60 public static function clearCacheGroups(array $clearGroups, array $cacheClients = array(0, 1))
61 {
62 $conf = JFactory::getConfig();
63
64 foreach ($clearGroups as $group)
65 {
66 foreach ($cacheClients as $client_id)
67 {
68 try
69 {
70 $options = array(
71 'defaultgroup' => $group,
72 'cachebase' => ($client_id) ? JPATH_ADMINISTRATOR . '/cache' : $conf->get('cache_path', JPATH_SITE . '/cache')
73 );
74
75 $cache = JCache::getInstance('callback', $options);
76 $cache->clean();
77 }
78 catch (Exception $e)
79 {
80 // suck it up
81 }
82 }
83 }
84 }
85 }