mesavolt/simple-cache-bundle 问题修复 & 功能扩展

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

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

mesavolt/simple-cache-bundle

Composer 安装命令:

composer require mesavolt/simple-cache-bundle

包简介

Symfony integration for mesavolt/simple-cache

README 文档

README

Latest Stable Version License

Integrate mesavolt/simple-cache into your Symfony app.

By default, it writes the cache to disk in the cache directory of Symfony (%kernel.cache_dir%) and uses an empty namespace, but both these options can be configured.

Installation

Applications that use Symfony Flex

Open a command console, enter your project directory and execute:

composer require mesavolt/simple-cache-bundle

That's it. Flex automagically enables the bundle for you. Go to the Configuration section of this README to see how you can customize the bundle's behavior.

Applications that don't use Symfony Flex

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

composer require mesavolt/simple-cache-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Mesavolt\SimpleCacheBundle\SimpleCacheBundle(),
        );

        // ...
    }

    // ...
}

Configuration

The following options are available to customize the behavior of the bundle's cache service :

Option name Default value Role
simple_cache.cache_dir %kernel.cache_dir% Where the cache is written to disk
simple_cache.namespaces simple-cache Default cache namespace

Applications that don't use Symfony Flex

Create config/services/simple_cache.yaml and tweak its content :

simple_cache:
    namespaces: 
      - default
      - specific
    cache_dir: /tmp/cache

Applications that don't use Symfony Flex

Add this to your app/config/config.yml file and tweak the options :

simple_cache:
    namespaces:
      - default
      - specific
    cache_dir: /tmp/cache

Usage

To retrieve a Mesavolt\SimpleCache instance, you can:

  • inject the cache attached to the first namespace from the namespaces option by type-hinting Mesavolt\SimpleCache
  • get the mesavolt.simple_cache.default or mesavolt.simple_cache.specific services from the container,
  • inject the Mesavolt\SimpleCacheBundle\SimpleCachePool service and get a cache by its namespace with the getCache($namespace) method
<?php

namespace App;


use Mesavolt\SimpleCache;
use Mesavolt\SimpleCacheBundle\SimpleCachePool;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\Response;

class HomeController extends AbstractController
{
    public function demo1(SimpleCache $cache): Response
    {
        // $cache is the cache configured with the 'default' namespace
        $time = $cache->get('val', function () {
            return time();
        }, SimpleCache::TTL_30_MINUTES);
        
        return $this->render('home/demo.html.twig', [
            'time' => $time
        ]);
    }

    public function demo2(): Response
    {
        $time = $this->get('mesavolt.simple_cache.default')->get('val', function () {
            return time();
        }, SimpleCache::TTL_30_MINUTES);

        return $this->render('home/demo.html.twig', [
            'time' => $time
        ]);
    }

    public function demo3(SimpleCachePool $pool): Response
    {
        $time = $pool->getCache('specific')->get('val', function () {
            return time();
        }, SimpleCache::TTL_30_MINUTES);

        return $this->render('home/demo.html.twig', [
            'time' => $time
        ]);
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-06-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固