/** * Delete key(s) matching a regular expression, and/or scope, and/or bundle * * @param integer/boolean $bundle_id * @param string $session_id * @param integer $site_id * @param string $regex a regular expression * @param integer $invalidate Delay until cached item expires (seconds) * @return boolean */ function delete_matching_keys($bundle_id = FALSE, $session_id = NULL, $site_id = 1, $regex = NULL, $invalidate = 0) { $deleted = FALSE; // have keys been deleted from the database? $clear_static = TRUE; // attempt to delete corresponding *individual* static cache files? // Can we clear the entire static cache in one go (to minimize disk access)? if ($this->EE->config->item('stash_static_cache_enabled') && $regex == NULL && $invalidate == 0) { if (!$bundle_id || $this->_can_static_cache($bundle_id)) { if (is_null($session_id) || $session_id === 'site' || $session_id === 'all') { $this->_delete_dir('/', $site_id); $clear_static = FALSE; } } } // clear the db $this->db->where('site_id', $site_id); // match a specific bundle if ($bundle_id) { $this->db->where('bundle_id', $bundle_id); } // match session_id if (!is_null($session_id)) { // scope supplied? if ($session_id === 'user') { // all user-scoped variables $this->db->where('session_id !=', '_global'); } elseif ($session_id === 'site') { // all site-scoped variables $this->db->where('session_id', '_global'); } else { // a specific user session $this->db->where('session_id', $session_id); } } // match key_name regex if (!is_null($regex)) { $this->db->where('key_name RLIKE ', $this->db->escape($regex), FALSE); } // get matching keys $query = $this->db->select('id, site_id, key_name, key_label, session_id, bundle_id')->get('stash'); if ($query->num_rows() > 0) { $deleted = $this->delete_cache($query->result(), $clear_static, $invalidate); } if ($deleted) { // deleted sucessfully, reset the static key cache self::$keys = array(); } return $deleted; }
/** * Delete key(s) matching a regular expression, and/or scope, and/or bundle * * @param integer/boolean $bundle_id * @param string $session_id * @param integer $site_id * @param string $regex a regular expression * @return boolean */ function delete_matching_keys($bundle_id = FALSE, $session_id = NULL, $site_id = 1, $regex = NULL) { $deleted = FALSE; $this->db->where('site_id', $site_id); // match a specific bundle if ($bundle_id) { $this->db->where('bundle_id', $bundle_id); } // match session_id if (!is_null($session_id)) { // scope supplied? if ($session_id === 'user') { // all user-scoped variables $this->db->where('session_id !=', '_global'); } elseif ($session_id === 'site') { // all site-scoped variables $this->db->where('session_id', '_global'); } else { // a specific user session $this->db->where('session_id', $session_id); } } // match key_name regex if (!is_null($regex)) { $this->db->where('key_name RLIKE ', $this->db->escape($regex), FALSE); // get matching keys $query = $this->db->select('id, key_name, key_label, bundle_id, session_id')->get('stash'); if ($query->num_rows() > 0) { $deleted = $this->delete_cache($query->result(), $site_id); } } elseif ($this->db->delete('stash')) { // ------------------------------------- // 'stash_delete' hook // ------------------------------------- if ($this->EE->extensions->active_hook('stash_delete') === TRUE) { $this->EE->extensions->call('stash_delete', array('key_name' => FALSE, 'key_label' => FALSE, 'bundle_id' => $bundle_id, 'session_id' => $session_id, 'site_id' => $site_id)); } // delete entire static cache for this site if bundle is 'static' or not specified // and scope is 'site', 'all' or not specified if (!$bundle_id || $this->_can_static_cache($bundle_id)) { if (is_null($session_id) || $session_id === 'site' || $session_id === 'all') { $this->_delete_dir('/', $site_id); } } $deleted = TRUE; } if ($deleted) { // deleted sucessfully, reset the static key cache self::$keys = array(); } return $deleted; }