This document discusses caching techniques in Yii framework including content caching, query caching, fragment caching, and full-page caching. It provides examples of using the cache component's get() and set() methods for content caching. For query caching, it demonstrates using CDbCacheDependency to configure cache expiration when database records change. Fragment caching allows caching blocks of content at once in view files. Full-page caching caches entire page contents by bypassing action output.
3. 1. Model-View-Controller (MVC) design pattern.
2. Form input and validation.
3. AJAX-enabled widgets.
4. Internationalization (I18N) and localization (L10N).
5. Automatic code generation.
6. Friendly with third-party code.
7. Caching
4.
5.
6.
7.
8.
9.
10.
11.
12. - how to use the Zend_Search_Lucene component from the Zend framework in a
Yii application.
- First, we extract the Zend framework release file to a directory
under protected/vendors, assuming protected is the application base directory.
Verify that the file protected/vendors/Zend/Search/Lucene.php exists.
- In Controller Add
Yii::import('application.vendors.*');
require_once('Zend/Search/Lucene.php');
-In Action
$lucene=new Zend_Search_Lucene($pathOfIndex);
$hits=$lucene->find(strtolower($keyword));
13. Why we are using caching?
1. Provide better user experience.
2. Improve sever performance.
3. Reduce database load.
14. Type of Caching in YII?
1. Content Caching.
2. Query Caching.
3. Fragment Caching.
4. Full-Page Caching
15. - Use the get() and set() methods of the cache component
to retrieve and store content in the cache
Example:
YII::app()->cache->set($id,$value,$tti);
$value = YII::app()->cache->get($id);
If($value == false)
{
Regenerate $value if not found in cache
}
16. - For Query Caching YII using CDbDependency to Configure
The cache to expire when there is a change in the update_time
column OR time .
Example.
$sql = “Select * FROM tbl_product”;
$dependency = new CDbCacheDependency(“Select MAX(update_time)
FROM tbl_product”);
$products = YII::app()->db->cache(120,$dependency)-
>createCommand($sql)->queryAll();
17. - Fragment caching allows you to cache a block of content all
at once. Typically used in view files.
Example.
if($this->beginCache($id,array(‘duration’=>120)))
{
echo “this is fragment caching”;
$this->endCache();
}
echo “this is fragment caching without cache”;
18. - Page Caching allows you to cache the entire contents of
page. We have to bypass the action output in order to cache all page
contents
Example.
Public function filters()
{
return array(
array(
‘COutputCache + index’,
‘dureation’=>60,
‘varyByRoute’=>true,
),
);
}