Skip to content

Commit

Permalink
Add CI_Output::delete_cache()
Browse files Browse the repository at this point in the history
(an improved version of PR bcit-ci#609)
  • Loading branch information
narfbg committed Nov 30, 2012
1 parent 4173823 commit b37d2bc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
39 changes: 39 additions & 0 deletions system/core/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,45 @@ public function _display_cache(&$CFG, &$URI)

// --------------------------------------------------------------------

/**
* Delete cache
*
* @param string $uri URI string
* @return bool
*/
public function delete_cache($uri = '')
{
$CI =& get_instance();
$cache_path = $CI->config->item('cache_path');
if ($cache_path === '')
{
$cache_path = APPPATH.'cache/';
}

if ( ! is_dir($cache_path))
{
log_message('error', 'Unable to find cache path: '.$cache_path);
return FALSE;
}

if (empty($uri))
{
$uri = $CI->uri->uri_string();
}

$cache_path .= md5($CI->config->item('base_url').$CI->config->item('index_page').$uri);

if ( ! @unlink($cache_path))
{
log_message('error', 'Unable to delete cache file for '.$uri);
return FALSE;
}

return TRUE;
}

// --------------------------------------------------------------------

/**
* Set Cache Header
*
Expand Down
4 changes: 2 additions & 2 deletions user_guide_src/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ Release Date: Not Released
- Renamed method ``_call_hook()`` to ``call_hook()`` in the :doc:`Hooks Library <general/hooks>`.
- :doc:`Output Library <libraries/output>` changes include:
- Added a second argument to method ``set_content_type()`` that allows setting the document charset as well.
- Added method ``get_content_type()``.
- Added method ``get_header()``.
- Added methods ``get_content_type()`` and ``get_header()``.
- Added method ``delete_cache()``.
- ``$config['time_reference']`` now supports all timezone strings supported by PHP.
- :doc:`Config Library <libraries/config>` changes include:
- Changed ``site_url()`` method to accept an array as well.
Expand Down
12 changes: 10 additions & 2 deletions user_guide_src/source/general/caching.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,13 @@ If you no longer wish to cache a file you can remove the caching tag and
it will no longer be refreshed when it expires.

.. note:: Removing the tag will not delete the cache immediately. It will
have to expire normally. If you need to remove it earlier you
will need to manually delete it from your cache directory.
have to expire normally.

If you need to manually delete the cache, you can use the ``delete_cache()``
method::

// Deletes cache for the currently requested URI
$this->output->delete_cache();

// Deletes cache for /foo/bar
$this->output->delete_cache('/foo/bar');

0 comments on commit b37d2bc

Please sign in to comment.