From 9b3e7b5f2d4ec4feae793ef90454506addbb19e1 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 4 Feb 2008 23:20:34 +0000 Subject: Added and documented Active Record caching. Made AR fully database-prefix aware --- user_guide/database/active_record.html | 39 ++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'user_guide/database') diff --git a/user_guide/database/active_record.html b/user_guide/database/active_record.html index 12c59e14b..9a75992fa 100644 --- a/user_guide/database/active_record.html +++ b/user_guide/database/active_record.html @@ -78,6 +78,7 @@ is generated by each database adapter. It also allows for safer queries, since
  • Updating Data
  • Deleting Data
  • Method Chaining
  • +
  • Active Record Caching
  • @@ -698,8 +699,8 @@ $this->db->truncate('mytable');
    // TRUNCATE mytable

    Note: If the TRUNCATE command isn't available, truncate() will execute as "DELETE FROM table".

    -  -

    Method Chaining

    + +

     Method Chaining

    Method chaining allows you to simplify your syntax by connecting multiple functions. Consider this example:

    @@ -710,8 +711,38 @@ $query = $this->db->get();

    Note: Method chaining only works with PHP 5.

    - - +

     

    + +

     Active Record Caching

    +

    While not "true" caching, Active Record enables you to save (or "cache") certain parts of your queries for reuse later. Normally, when an Active Record call is completed, all stored information is reset for the next call. With caching, you can prevent this reset, and reuse information easily.

    +

    Cached calls are cumulative.  If you makes 2 cached select() calls, and then 2 uncached select() calls, this will result in 4 select() calls. There are three Caching functions available:

    +

    $this->db->start_cache()

    +

    This function must be called to begin caching. All Active Record queries of the correct type (see below for supported queries) are stored for later use.

    +

    $this->db->stop_cache()

    +

    This function can be called to stop caching.

    +

    $this->db->flush_cache()

    +

    This function deletes all items from the Active Record cache.

    +

    Here's a usage example:

    +

    $this->db->start_cache();
    + $this->db->select('field1');
    + $this->db->stop_cache();
    + $this->db->get('tablename');
    + // Results in:
    + // SELECT `field1` FROM (`tablename`)
    +
    + this->db->select('field2');
    + $this->db->get('tablename');
    + // Results in:
    + // SELECT `field1`, `field2` FROM (`tablename`)
    +
    + $this->db->flush_cache();
    +
    + this->db->select('field2');
    + $this->db->get('tablename');
    + // Results in:
    + // SELECT `field2` FROM (`tablename`)

    +

    Note: The following fields can be cached: ‘select’, ‘from’, ‘join’, ‘where’, ‘like’, ‘groupby’, ‘having’, ‘orderby’, ‘set’

    +

     

    -- cgit v1.2.3-24-g4f1b