sinsquare/silex-doctrine-cache-provider 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

sinsquare/silex-doctrine-cache-provider

Composer 安装命令:

composer require sinsquare/silex-doctrine-cache-provider

包简介

Doctrine cache provider for Silex framework

README 文档

README

Code quality Tests Issues
SensioLabsInsight Build Status Issue Count
Codacy Badge Test Coverage
Code Climate

Installation

With composer :

{
    "require": {
        "sinsquare/silex-doctrine-cache-provider": "1.*"
    }
}

Usage

You can use the provider with Pimple or Silex.

First you have to create the condig for the cache, than you have to register the DoctrineCacheServiceProvider.

<?php

use SinSquare\Cache\DoctrineCacheServiceProvider;

$container = new Container();
$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache_name_1' => array(
            'type' => 'void',
        ),
    ),
);

$container->register(new DoctrineCacheServiceProvider());

To access a cache, you can either get if with the $container['doctrine.caches'][] or with $container['doctrine.cache.<cache_name>']

<?php

$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache_name_1' => array(
            'type' => 'void',
        ),
    ),
);

$container->register(new DoctrineCacheServiceProvider());

$cache = $container['doctrine.caches']['cache_name_1'];
//OR
$cache = $container['doctrine.caches.cache_name_1'];

Options

Available cache types:

APC

$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'apc'
        ),
    ),
);

APCu

$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'apcu'
        ),
    ),
);

Array

$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'array'
        ),
    ),
);

Chain

$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'chain',
            'caches' => array('cache_1', 'cache_2')
        ),
        'cache_1' => array(
            'type' => 'array'
        ),
        'cache_2' => array(
            'type' => 'apc'
        ),
    ),
);

Filesystem

$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'filesystem',
            'directory' => 'dir',
			'extension' => 'value' //optional
			'umask' => 'value' //optional
        )
    ),
);

Filesystem

$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'filesystem',
            'directory' => 'dir',
			'extension' => 'value' //optional
			'umask' => 'value' //optional
        )
    ),
);

PHP file

$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'phpfile',
            'directory' => 'dir',
			'extension' => 'value' //optional
			'umask' => 'value' //optional
        )
    ),
);

Memcache

$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'memcache',
            'host' => 'host',
			'port' => 'port'
        )
    ),
);

Memcached

$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'memcached',
            'host' => 'host',
			'port' => 'port'
        )
    ),
);

Void

$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'void'
        )
    ),
);

Creating custom cache

For creating a new cache provider all you have to do is the following:

  • create the new CacheType
  • define the $container['doctrine.cache.factory.']
  • use the new provider in the config

Creating the new Cache type

<?php

namespace Your\Name\Space;

use Doctrine\Common\Cache\CacheProvider;

class MyCustomCache extends CacheProvider
{
//class body with the required methods and functionality
}

Create a factory for it

//you have to define this BEFORE you get a new cache, preferably before registering the provider
$container['doctrine.cache.factory.customcache'] = $container->protect(function ($cacheOptions) use ($container) {

	$namespace = $cacheOptions["namespace"];

	//

	return new MyCustomCache();

});

Use it

$container['doctrine.cache.options'] = array(
    'providers' => array(
        'cache' => array(
            'type' => 'customcache'
        )
    ),
);

//getting the cache is the same as before

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-02-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固