定制 sedpro/cachedecorator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sedpro/cachedecorator

Composer 安装命令:

composer require sedpro/cachedecorator

包简介

Simple cache decorator module for zf2 projects

README 文档

README

Version 0.1

This module allows you simple caching of your service methods.

The main idea was to create a caching module, which can be connected to a project without changing code. All you need to do is ajust your config.

Installation

For the installation uses composer composer.

php composer.phar require  sedpro/cachedecorator:dev-master

Add this project in your composer.json:

"require": { "sedpro/cachedecorator": "dev-master" }

Post Installation

Configuration:

  • Add the module of config/application.config.php under the array modules, insert Cachedecorator

  • Remove services, you want to cache, from getServiceConfig function in file Module.php

  • In your config/autoload/global.php file add two values:

      'caches' => [
          \Cachedecorator\Module::STORAGE => [
              'adapter' => [
                  'name' => 'memcached',
              ],
              'options' => [
                  'ttl' => 3600,
                  'servers' => [
                      'node0' => [
                          'host' => '127.0.0.1',
                          'port' => 11211,
                      ],
                  ],
                  'namespace' => 'some_ns:',
              ],
          ],
      ],
      \Cachedecorator\Module::METHODS => [
          'Application\Service\Example' => [
              'getItems',
          ],
      ],

'caches' contains all caches you use in project. They will be instantiate in abstact factory Zend\Cache\Service\StorageCacheAbstractServiceFactory which is called in vendor/sedpro/cachedecorator/config/module.config.php. If you are already using this factory, there will be no conflict.

'\Cachedecorator\Module::STORAGE' is cache storage adapter, used to store the output of your services.

'\Cachedecorator\Module::METHODS' is list of services you want to cache. Cached will be only listed functions.

Example

If you use the configuration, showed above, method getItems of class Application\Service\Example will be cached. You can use it as usual:

  $exampleService = $this->getServiceLocator()->get('Application\Service\Example');
  $items = $exampleService->getItems(); // cached
  $values = $exampleService->getValues(); // not cached

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-09-30