Stash_model::delete_key PHP Method

delete_key() public method

Delete key(s) by name, optionally limited to keys registered with the user session
public delete_key ( string $key, integer/boolean $bundle_id = FALSE, string $session_id = NULL, integer $site_id = 1, integer $invalidate ) : boolean
$key string
$bundle_id integer/boolean
$session_id string
$site_id integer
$invalidate integer Delay until cached item expires (seconds)
return boolean
    function delete_key($key, $bundle_id = FALSE, $session_id = NULL, $site_id = 1, $invalidate = 0)
    {
        $this->db->where('key_name', $key)->where('site_id', $site_id);
        // match a specific bundle
        if ($bundle_id) {
            $this->db->where('bundle_id', $bundle_id);
        }
        if (!is_null($session_id)) {
            $this->db->where('session_id', $session_id);
            if ($session_id !== '_global') {
                // make sure we only delete the user's variable
                $this->db->limit(1);
            }
        }
        // get matching key(s)
        $query = $this->db->select('id, site_id, key_name, key_label, session_id, bundle_id')->get('stash');
        if ($query->num_rows() > 0) {
            if ($this->delete_cache($query->result(), TRUE, $invalidate)) {
                // deleted, now remove the key from the internal key cache
                $cache_key = $key . '_' . $bundle_id . '_' . $site_id . '_' . $session_id;
                if (isset(self::$keys[$cache_key])) {
                    unset(self::$keys[$cache_key]);
                }
                return TRUE;
            }
        }
        return FALSE;
    }