DataMapper ORM

Query Caching Methods (simplecache)

To enable these methods, add 'simplecache' to DataMapper's config, under 'extensions'.

Enables the usage of CodeIgniter's simple query caching for large result sets.

Note that this is different than the start_cache and stop_cache methods, which are only used to cache ActiveRecord queries, and it is also different than the Production Cache, which is used to cache initialization information for models.


Gets the results of the current query. If a cached version is available, it uses that one, otherwise it runs the query and saves it for later. You can pass in any arguments that you would pass in to DataMapper's get method.

Like CodeIgniter's caching, this method requires that the query always be on the exact same URL, and have the exact same structure. It may or may not improve performance. Please read the CodeIgniter Documentation for more information.

General Usage

$post = new Post();
// There are a lot of posts, so cache if possible.


On the next call to get_cached, the cache will be cleared. You can also forcibly clear the cache for a specific URI by passing in the URI segments.

General Usage:

$should_clear_cache = ? // Look up whether or not this cache needs to be cleared

Clearing the Cache on Save


// Need to clear the caches for large post queries
$post->clear_cache('welcome');      // index.php/welcome
$post->clear_cache('posts', 'all'); // index.php/posts/all