定制 moust/silex-cache 二次开发

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

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

moust/silex-cache

最新稳定版本:v2.0.2

Composer 安装命令:

composer require moust/silex-cache

包简介

Cache service provider for Silex application

README 文档

README

Build Status

Silex Cache Service Provider

The Silex Cache service provider allows you to use several PHP opcode cache in your Silex application.

Installation

To enable it, add this dependency to your composer.json file:

{ "require": { "moust/silex-cache": "~2.0" } }

Parameters

  • cache.options: Array of cache options.
    • driver: The cache driver to use. Can be any of: apc,apcu, array, file, memcache, memcached, xcache, redis, wincache.
    • cache_dir: Only relevant for file cache driver, specifies the path to the cache directory
    • memcache: Only relevant for memcache cache driver, provide the Memcache instance to use. If not defined, a default Memcache object will be instanciated. See the Memcache documentation for additional informations : PHP: Memcache - Manual
    • memcached: Only relevant for memcached cache driver, provide the Memcached instance to use. If not defined, a default Memcached object will be instanciated. See the Memcached documentation for additional informations : PHP: Memcached - Manual
    • redis: Only relevant for redis cache driver, provide the Redis instance to use. If not defined, a default Redis object will be instanciated. See the PhpRedis documentation for additional informations : PhpRedis

Registering

$app->register(new Moust\Silex\Provider\CacheServiceProvider(), array( 'cache.options' => array( 'driver' => 'apc' ) ));

Usage

The Cache provider provides a cache service. Here is a usage example:

// stores a variable $app['cache']->store('foo', 'bar'); // stores a variable with a 1 minute lifetime $app['cache']->store('foo', 'bar', 60); // fetch variable echo $app['cache']->fetch('foo'); // delete variable $app['cache']->delete('foo'); // clear all cached variables $app['cache']->clear();

Using multiple caches

The Cache provider can allow access to multiple caches. In order to configure the cache drivers, replace the cache.options with caches.options. caches.options is an array of configurations where keys are cache names and values are options:

$app->register(new Moust\Silex\Provider\CacheServiceProvider(), array( 'caches.options' => array( 'apc' => array( 'driver' => 'apc' ), 'filesystem' => array( 'driver' => 'file', 'cache_dir' => './temp' ), 'memory' => array( 'driver' => 'array' ), 'memcache' => array( 'driver' => 'memcache', 'memcache' => function () { $memcache = new \Memcache; $memcache->connect('localhost', 11211); return $memcache; } ) ) ));

The first registered cache is the default and can simply be accessed as you would if there was only one. Given the above configuration, these two lines are equivalent:

$app['cache']->store('foo', 'bar'); $app['caches']['apc']->store('foo', 'bar');

Licence

Copyright (c) 2014 Quentin Aupetit

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

统计信息

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

GitHub 信息

  • Stars: 33
  • Watchers: 5
  • Forks: 19
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固