Difference between #5 and #4 of How to make use of a fragment cache

unchanged
Title
How to make use of a fragment cache
unchanged
Category
Tutorials
unchanged
Tags
changed
Content
From
[http://jp.php.net/manual/en/memcache.installation.php](http://jp.php.net/manual/en/memcache.installation.php);

* Download & install libevent (memcached dependency)
~~~
$ wget http://www.monkey.org/~provos/libevent-1.4.8-stable.tar.gz
$ tar xfz libevent-1.4.8-stable.tar.gz
$ cd libevent-1.4.8-stable
$ ./configure && make && sudo make install
~~~

* Create a symlink to libevent
~~~
$ sudo ln -s /usr/local/lib/libevent-1.4.so.2 /usr/lib
~~~

* Download & install memcached
~~~
$ wget http://danga.com/memcached/dist/memcached-1.2.6.tar.gz
$ tar xfz memcached-1.2.6.tar.gz
$ cd memcached-1.2.6
$ ./configure && make && sudo make install
~~~

* Run memcached as a daemon
~~~
# memcached -d -m 1024 -u root -l 127.0.0.1 -p 11211
~~~

* Configure cache application component in the configure file
(protected/config/main.php).
~~~
[php]

             'cache'=>array(
                 'class'=>'system.caching.CMemCache',
                 'servers'=>array(
                            array('host'=>'localhost', 'port'=>11211,
'weight'=>60),
                     ),
                 ),
~~~

* Insert beginCache()/endCache() statement in front of/after the widget.
~~~
[php]

    <?php if($this->beginCache('tagCloud', array('duration'=>60))) {
?>
    <?php $this->widget('TagCloud'); ?>
    <?php $this->endCache(); } ?>

    <?php if($this->beginCache('RecentPosts', array('duration'=>60))) {
?>
    <?php $this->widget('RecentPosts'); ?>
    <?php $this->endCache(); } ?>

    <?php if($this->beginCache('RecentComments',
array('duration'=>60))) { ?>
    <?php $this->widget('RecentComments'); ?>
    <?php $this->endCache(); } ?>
~~~

Please> Note: Please be careful to use the cache,
because it increases the performance of the application, but decreases the
interactivity.
Write new article
  • Written by: dalip
  • Updated by: wei
  • Category: Tutorials
  • Votes: +1
  • Viewed: 5,418 times
  • Created on: Feb 21, 2009
  • Last updated: Oct 25, 2010
  • Tags: cache, memcache