定制 rickysu/tagcache-bundle 二次开发

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

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

rickysu/tagcache-bundle

Composer 安装命令:

composer require rickysu/tagcache-bundle

包简介

This bundle provides cache with tags and controller cache

README 文档

README

Introduction

This bundle provides cache with tags.

Features

  • Stores a cache with multiple tags. And deletes cache by using tag.
  • Provides controller cache.

Requirements

  • Annotations for Controllers.

Installation

editing the composer.json file in the root project.

Editing the composer.json under require: {} section add

"rickysu/tagcache-bundle": "1.0.*",

Update Bundle :

php composer.phar update

Instantiate Bundle :

<?php
//app/AppKernel.hpp
public function registerBundles()
{
   $bundles = array(
        // ...
        new RickySu\TagcacheBundle\TagcacheBundle(),
   );
}

Configuration

Configure cache adapter

# app/config/config.yml
tagcache:
    driver:                     Memcache
    debug:                      %kernel.debug%
    options:
        hashkey:                true
        enable_largeobject:     false
        cache_dir:              "%kernel.cache_dir%/tagcache"
        servers:
            -    'localhost:11211:10'
            -    'otherhost:11211:20'
# app/config/config_dev.yml
tagcache:
    namespace:                  'Name_Space_For_Your_Project:dev'
# app/config/config_prod.yml
tagcache:
    namespace:                  'Name_Space_For_Your_Project:prod'

driver

The cache driver. Currently support "Memcache,Memcached,File,Sqlite,Apc,Nullcache". Nullcache is for testing only.

hashkey

some driver like Memcached,only support 250 characters key length. Enable this option will use md5 hashed key.

enable_largeobject

Memcache cannot store object over 1MB.Enable these option will fix this issue,but cause lower performance.default false.

servers

Memcache server configs. format => "Host:Port:Weight"

How to Use

Using Tagcache for storing cache data.

<?php
$Tagcache=$container->get('tagcache');

//store cache with Tags:{TagA,TagB} for 300 secs.
$Tagcache->set('Key_For_Store','Data_For_Store',array('TagA','TagB'),300);

//get cache.
$Tagcache->get('Key_For_Store');

//delete cache.
$Tagcache->delete('Key_For_Store');

//delete cache by Tag.
$Tagcache->deleteTag('TagA');

//acquire a lock.If a lock already exists,It will be blocked for 5 secs.
$Tagcache->getLock('Your_Lock_Name',5);

//release a lock.
$Tagcache->releaseLock('Your_Lock_Name');

//increment a cache
$Tagcache->inc('Key_For_increment');

//decrement a cache
$Tagcache->dec('Key_For_decrement');

Controller Cache

Controller Setting

<?php
//in Controller
namespace Acme\DemoBundle\Controller;

// these import the "@Tagcache" annotations
use RickySu\TagcacheBundle\Configuration\Tagcache;

class DemoController extends Controller
{
    /**
     * @Route("/hello/{name}", name="_demo_hello")
     * @Tagcache(expires=600,cache=true)
     * @Template()
     */
    public function helloAction($name)
    {
        return array('name' => $name);
    }

    /**
     * @Route("/test", name="_demo_test")
     * @Tagcache(expires=600,tags={"TagA","TagB"},key="custom_cache_key",cache=true)
     * @Template()
     */
    public function testAction()
    {
        return;
    }
}

View Setting(Twig) (for Symfony 2.1)

{#in view render a controller#}
{%render 'AcmeDemoBundle:Demo:test' with {
     'tagcache':    {
           'key':    'custom_cache_key',
           'tags':   ['TagA','TagB'],
           'expires': 300
     }
}%}

View Setting(Twig) (for Symfony 2.2)

{#in view render a controller#}
{%render(
    controller(
        'AcmeDemoBundle:Demo:test',
        {
            'tagcache':    {
                'key':    'custom_cache_key',
                'tags':   ['TagA','TagB'],   
                'expires': 300
            }
        }
    )
)%}

Your Familiar Partial Cache Comes Back

first access

cached access

Clear Cache

app/console cache:clear

Note

If you both define cache params in view and controller. "tagcache" variable in view will overwrite controller annotations. But remember,controller annotation config "cache" must set to false,If you want to turn off controller cache.

TODO

LICENSE

MIT

rickysu/tagcache-bundle 适用场景与选型建议

rickysu/tagcache-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18.78k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2012 年 09 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cache」 「tag」 「rickysu」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 rickysu/tagcache-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 rickysu/tagcache-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 rickysu/tagcache-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-09-12