There are 3 main functions you will need to know
I. startBlock($id, $change_on_page = true, $depend_on = "", $post_safe = false, $cache_time = -1)
1.Description:
use this function to cache a single block of the page, actually this function can also be used for caching a whole page
2.Variables:
a. $id: the id of the block, assign anything you want, but it has to be unique
b. $change_on_page: some special block content changes depeding on which page is loading (for example, the listing of the products_all page is different from the contact_us page)
the default is true, if you think that specific block does not depend on which page is loading (some sidebox content can be a very good example)
c. $cache_time: set cache time in seconds, if you dont set it, it will use the default one set in admin
d. $post_safe: this is a bit hard to explain, but I'll try my best. When you submit a page with a post form, the content loaded on the new page will depend on this post form (i.e: when you add products to cart, you are submitting a post form)
Some block content doesnt have anything to do with post form, so it is post_form_safe (a category tree sidebox is a good example)
Some block content does depend on post form (a shopping cart content sidebox is a good example)
Whenever in doubt, set the post_form is false.
e. $depend_on: this is a new variable added to address 1 issue: certain part of the page is rendered based on certain info, for example the my account page should depend on each customer
So if you want to cache these pages you want to make sure you have it cached for each customer
II. startPage( $depend_on = "", $post_safe = false, $cache_time = -1)
1. Description:
use this function to cache the whole page
III. End()
1. You will see the use of this function in the example below
--------------------------------------------------------
Example of a single block cache:
<?php if(!SimpleCache::startBlock('centerColumn', true, false)): ?>
Now whatever block content goes here
<?php SimpleCache::End(); endif ?>
----------------------------------------------
Nested blocks
<?php if(!SimpleCache::startBlock('mainWrapper', true, false, 500)): ?>
Now whatever block content goes here
<?php if(!SimpleCache::startBlock('centerColumn', true, false, 900)): ?>
Now whatever block content goes here
<?php SimpleCache::End(); endif ?>
And some here
<?php SimpleCache::End(); endif ?>
Note that, in this very specific case, you can see that the outermost block has the cachetime less than the inner block, otherwise it would be meaning less to nest them
----------------------------------------------
Using depend_on
<?php if(!SimpleCache::startPage($_SESSION['customer_id'])): ?>
page content goes here
<?php SimpleCache::End(); endif ?>
-----------------------------------------------
Different caching rules for different page
<?php if(in_array($current_page_base, array('login', 'checkout_shipping', 'account')) ? !SimpleCache::startPage($_SESSION['customer_id']) : SimpleCache::startPage()): ?>
page content goes here
<?php SimpleCache::End(); endif ?>
In the example above, for certain pages we associate cache with customer id, the list above is just an example, if you want to go that way you will have a long list to go. The example just gives you the basic idea how to do it
------------------------------------------------
Avoide caching on certain pages
<?php if(in_array($current_page_base, array('login', 'checkout_shipping', 'account')) || !SimpleCache::startPage()) : ?>
page content goes here
<?php SimpleCache::End(); endif ?>
This may look like the previous example, but it is very different. Using the structure above will avoid caching all the pages in the array list.
I. startBlock($id, $change_on_page = true, $depend_on = "", $post_safe = false, $cache_time = -1)
1.Description:
use this function to cache a single block of the page, actually this function can also be used for caching a whole page
2.Variables:
a. $id: the id of the block, assign anything you want, but it has to be unique
b. $change_on_page: some special block content changes depeding on which page is loading (for example, the listing of the products_all page is different from the contact_us page)
the default is true, if you think that specific block does not depend on which page is loading (some sidebox content can be a very good example)
c. $cache_time: set cache time in seconds, if you dont set it, it will use the default one set in admin
d. $post_safe: this is a bit hard to explain, but I'll try my best. When you submit a page with a post form, the content loaded on the new page will depend on this post form (i.e: when you add products to cart, you are submitting a post form)
Some block content doesnt have anything to do with post form, so it is post_form_safe (a category tree sidebox is a good example)
Some block content does depend on post form (a shopping cart content sidebox is a good example)
Whenever in doubt, set the post_form is false.
e. $depend_on: this is a new variable added to address 1 issue: certain part of the page is rendered based on certain info, for example the my account page should depend on each customer
So if you want to cache these pages you want to make sure you have it cached for each customer
II. startPage( $depend_on = "", $post_safe = false, $cache_time = -1)
1. Description:
use this function to cache the whole page
III. End()
1. You will see the use of this function in the example below
--------------------------------------------------------
Example of a single block cache:
<?php if(!SimpleCache::startBlock('centerColumn', true, false)): ?>
Now whatever block content goes here
<?php SimpleCache::End(); endif ?>
----------------------------------------------
Nested blocks
<?php if(!SimpleCache::startBlock('mainWrapper', true, false, 500)): ?>
Now whatever block content goes here
<?php if(!SimpleCache::startBlock('centerColumn', true, false, 900)): ?>
Now whatever block content goes here
<?php SimpleCache::End(); endif ?>
And some here
<?php SimpleCache::End(); endif ?>
Note that, in this very specific case, you can see that the outermost block has the cachetime less than the inner block, otherwise it would be meaning less to nest them
----------------------------------------------
Using depend_on
<?php if(!SimpleCache::startPage($_SESSION['customer_id'])): ?>
page content goes here
<?php SimpleCache::End(); endif ?>
-----------------------------------------------
Different caching rules for different page
<?php if(in_array($current_page_base, array('login', 'checkout_shipping', 'account')) ? !SimpleCache::startPage($_SESSION['customer_id']) : SimpleCache::startPage()): ?>
page content goes here
<?php SimpleCache::End(); endif ?>
In the example above, for certain pages we associate cache with customer id, the list above is just an example, if you want to go that way you will have a long list to go. The example just gives you the basic idea how to do it
------------------------------------------------
Avoide caching on certain pages
<?php if(in_array($current_page_base, array('login', 'checkout_shipping', 'account')) || !SimpleCache::startPage()) : ?>
page content goes here
<?php SimpleCache::End(); endif ?>
This may look like the previous example, but it is very different. Using the structure above will avoid caching all the pages in the array list.