mohit-mingh/zf2booster

该软件包的最新版本(dev-master)没有提供许可证信息。

这是一个简单的模块,用于在ZF2中设置两种不同的缓存机制,以提高您网站的性能。

dev-master 2014-10-14 12:50 UTC

This package is not auto-updated.

Last update: 2024-09-24 02:14:21 UTC


README

这是一个简单的模块,用于在ZF2中设置两种不同的缓存机制,以提高您网站的性能。

第一:文件系统

为此,创建一个名为cache的文件夹。


> mkdir data/cache

现在给cache文件夹赋予权限0777。


> sudo chmod -R 0777 data/cache

现在您可以在系统中使用文件系统缓存。

文件系统缓存的设置

//ZF2Booster/config/booster.config.php

'fileCache' => array(
                    'cache_dir' => './data/cache',
                    'namespace' => 'systemCache',
                    'dir_level' => 2,
                    'filePermission' => 0666,
                    'dirPermission' => 0755
                    ),

这些都是默认的文件系统缓存设置。

使用

//ZF2Booster/src/ZF2Booster/Controller/ZF2BoosterController.php

// store item in filesystem cache
        $this->getServiceLocator()->get('Zend\Cache\Storage\Filesystem')->setItem('foo', 'taxi');
        

这是如何在文件系统缓存中存储项的方法。

//ZF2Booster/src/ZF2Booster/Controller/ZF2BoosterController.php

 // get item from filesystem cache
        echo 'Cached Item is:- '.$this->getServiceLocator()->get('Zend\Cache\Storage\Filesystem')->getItem('foo');
        

这是如何获取项的方法。

第二:memcached

这是一个分布式内存对象缓存系统

要使用此缓存,您必须安装PHP ext/memcached扩展。


> sudo apt-get update
> sudo apt-get install memcached
> sudo apt-get install php5-memcache
> sudo apt-get install php5-memcached

这样就完成了,现在您可以使用memcached。

设置

//ZF2Booster/config/booster.config.php

    'memcached' => array(
    	           'lifetime' => 7200,
                    'options' => array(
                                'servers'   => array(
                                    array(
                                        '127.0.0.1',11211 // For me my localhost is my memcached server.
                                    )
                                ),
                                'namespace'  => 'SystemMemCache',
                                'liboptions' => array (
                                    'COMPRESSION' => true,
                                    'binary_protocol' => true,
                                    'no_block' => true,
                                    'connect_timeout' => 100
                                )
                            )

这是memcached的默认设置。

使用

//ZF2Booster/src/ZF2Booster/Controller/ZF2BoosterController.php

// store item in memcached cache
        $this->getServiceLocator()->get('Zend\Cache\Storage\Memcached')->setItem('foo', 'taxi');
        

这是如何在memcached中存储项的方法。

//ZF2Booster/src/ZF2Booster/Controller/ZF2BoosterController.php

 // get item from memcached cache
        echo 'Cached Item is:- '.$this->getServiceLocator()->get('Zend\Cache\Storage\Memcached')->getItem('foo');
        

这是如何获取项的方法。

最后注意:-

我创建了这两个缓存服务,以便您可以在应用程序中使用它们。有关更多信息,请访问

http://framework.zend.com/manual/2.0/en/modules/zend.cache.storage.adapter.html