CodeIgniter Smart Cache Library

Smart cache library was created to over come the limitation in Codeginiter output caching. In CodeIgniter output caching when a valid cache file exists for a request then the controller is not executed at all and you don't have a control when to to serve from cach once you have created the cache file. In the Smart cache library you serve the cache and can do more than that.

PCG utilize this library where ever applicable to make the generated websites faster. You can download smart cache library for free from our GitHub source.

Features

  • Cache/Retrieve the cache using the library provided methods allows user to execute their code before reading from cache. Also user can cache the output when his conditions are met. For example it is not required to cache the user sensitive information. So caching and reading from cache can be done only when users are not logged.
  • Allows to keep sub views and/or session variables as dynamic when caching the output.
  • Allows to provide folder path while caching to group the cached pages and provides method to remove all the caches for the group. Useful when caching search results need to remove all the caches with any search key when an entry added/deleted/updated.

Available Functions

  • save_data ($filename,$data,$expiry)

    This functions save the data with the given file name and expiry date.

    $filename is the relative path from the cache root directory.

    $data is what needs to be stored in the file. Generally we save the output HTML from the views.

    $expiry is the default expiry time for the cached data. If not provided the data will be cached for unlimited time unless it is not deleted by using the delete_data or delete_all_data methods.

  • save_output($filename,$expiry)
    This function can be used to quickly cache the current CodeIgniter output buffer. The save_data() function also can be used for the same purpose by using the CodeIgniter buffer as the $data parameter.
  • get_data($filename)

    This function reads the data from the filename and return the content of it. Please note that if the file expiry is passed then FALSE is returned from this function.

    $filename will be same as the relative file path used when saving the data.

  • get_to_output($filename)

    This is same as get_data($filename) function but place the output directly in the CodeIgniter output buffer..

    Returns TRUE when output is replaced by cache and FALSE when no cache exists.

  • delete_data($filename)

    Delete the cache file by filename.

  • delete_all_data(directory_name)

    Delete all the caches files in the given directory.

Questions?

Please send your questions using the contact us form.