Developed with love by KnpLabs Hire us for your project!
20

KitpagesSimpleCacheBundle

by kitpages

This is a very simple cache system

KitpagesSimpleCacheBundle

Very simple cache system for symfony2. The cache data are saved in one table in
database.

author : Philippe Le Van (twitter : @plv)
http://www.kitpages.fr/fr/cms/102/kitpagessimplecachebundle

Installation

hum... as usual...

put the code in vendors/Kitpages/SimpleCacheBundle

add vendors/ in the app/autoload.php

add the new Bundle in app/appKernel.php

You need to create a table in the database :

CREATE TABLE `simple_cache_backend` (
  `id` varchar(255) NOT NULL,
  `data` longtext COMMENT '(DC2Type:array)',
  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL,
  `expired_at` datetime default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

(or you can use php app/console doctrine:schema:update)

Users Guide

1/ record & retrieve into/from the cache

$cacheManager = $this->get('kitpages.simple_cache');
$html = $cacheManager->get(
    'my-cache-uniq-id-12',
    function() {
        $output = "hello world";
        sleep (3);
        return $output;
    }
);

2/ clear the cache

$cacheManager = $this->get('kitpages.simple_cache');
$cacheManager->clear('my-cache-uniq-id-12');

3/ a more complex example : arguments given to the callback and expiration

$html = $cacheManager->get(
    'my-cache-uniq-id-12',
    function($arg1, $arg2) {
        $output = "hello world";
        sleep (3);
        return $output;
    },
    array(12, 34),
    $myExpirationTimeInSeconds
);

4/ multiple delete in the cache

$cacheManager = $this->get('kitpages.simple_cache');
$cacheManager->clear('my-cache-%');
// remove all the entries in the cache beginning by "my-cache-"
Copyright (c) 2011 Philippe Le Van (@plv) Kitpages - http://www.kitpages.fr

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.
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago
  • Merge pull request #3 from FaizalPribadi/patch-1
    By philippe-levan, 7 months ago