Git Product home page Git Product logo

doctrinecachetoolbar's Introduction

DoctrineCacheToolbar

Software License Build Status Code Coverage

DoctrineCacheToolbar is a Zend Framework 2/3 module which is integrated with Doctrine 2.
It does show statistics for regions while Second Level Cache is enabled in doctrine's configuration

Statistics in DoctrineCacheToolbar

Installation

You can install this module by cloning this project into your ./vendor/ directory, or using composer, which is more recommended:
1. Add this project into your composer.json

"require": {
    "szmnmichalowski/doctrine-cache-toolbar": "dev-master"
}

2. Update your dependencies

$ php composer.phar update

3. Add module to your application.config.php. It requires DoctrineModule, DoctrineORMModule and ZendDeveloperTools.

return array(
    'modules' => array(
        'DoctrineModule',
        'DoctrineORMModule',
        'ZendDeveloperTools',
        'DoctrineCacheToolbar' // <- Add this line
    )
);

Usage

This module does NOT need any configuration to work. It will show statistics for cache regions if you have Second Level Cache enabled.

What is a Second Level Cache?

Second Level Cache is a Doctrine's feature added in version 2.5. It allows to cache entity with their associations. More information you can find on Doctrine's website http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/second-level-cache.html

How to configure Second Level Cache in Zend Framework 2/3?

Add following code to Doctrine's configuration file:

'doctrine' => [
    'configuration' => [
        'orm_default' => [
            'metadata_cache'    => 'filesystem', // name of cache adapter
            'query_cache'       => 'filesystem', // name of cache adapter
            'result_cache'      => 'filesystem', // name of cache adapter
            'hydration_cache'   => 'filesystem', // name of cache adapter
            'second_level_cache' => [
                'enabled'               => true,
                'default_lifetime'      => 300,
                'default_lock_lifetime' => 300,
                'file_lock_region_directory' => __DIR__.'../../data/cache',
            ]
        ]
    ]
]

You can also define regions and lifetime for each of them. Add following array inside second_level_cache index:

'regions' => [
    'my_region_name' => [
        'lifetime' => 100,
        'lock_lifetime' => 200
    ],
]

Then, in your entity add:

namespace Application\Entity;
    
use Doctrine\ORM\Mapping AS ORM;
    
/**
 * @ORM\Entity
 * @ORM\Table(name="app_post")
 * @ORM\Cache("NONSTRICT_READ_WRITE", region="my_region_name")
 */
class Post
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
        
    /**
     * @ORM\Column(type="string", length=40, nullable=false)
     */
    private $title;
}

From now toolbar should show statistics similar to this one on image above.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.