Giter Club home page Giter Club logo

cache-bundle's Introduction

This Bundle is Deprecated

This bundle has been replaced by PHP-Cache. Check it out!

Aequasi cache-bundle Build Status

Cache Bundle for Symfony 2

Creates services in Symfony 2, for cache, that can also be used with doctrines three cache types (metadata, result, and query). It also provides functionality for session handler support, and Router support.

The respective cache extensions will be required for your project.

Redis uses the php redis extension.

Requirements

  • PHP >= 5.6, < 7.1
  • Symfony >= 2.7, < 4.0
  • Composer

To Install

Run the following in your project root, assuming you have composer set up for your project

composer.phar require aequasi/cache-bundle

Add the bundle to app/AppKernel.php

$bundles(
    ...
       new Aequasi\Bundle\CacheBundle\AequasiCacheBundle(),
    ...
);

Then add parameters (probably in config.yml) for your servers, and options

aequasi_cache:
    instances:
        default:
          persistent: true # Boolean or persistent_id
          namespace: mc
          type: memcached
          hosts:
              - { host: localhost, port: 11211 }

To see all the config options, run php app/console config:dump-reference aequasi_cache to view the config settings

Doctrine

This bundle allows you to use its services for Doctrine's caching methods of metadata, result, and query.

If you want doctrine to use this as the result and query cache, add this

aequasi_cache:
    doctrine:
        enabled: true
        metadata:
            instance: default
            entity_managers:   [ default ]          # the name of your entity_manager connection
            document_managers: [ default ]       # the name of your document_manager connection
        result:
            instance: default
            entity_managers:   [ default, read ]  # you may specify multiple entity_managers
        query:
            instance: default
            entity_managers: [ default ]

Session

This bundle even allows you to store your session data in one of your cache clusters. To enable:

aequasi_cache:
    session:
        enabled: true
        instance: default
        prefix: "session_"
        ttl: 7200

Router

This bundle also provides router caching, to help speed that section up. To enable:

aequasi_cache:
    router:
        enabled: true
        instance: default

If you change any of your routes, you will need to clear all of the route_* keys in your cache.

To Use

To use this with doctrine's entity manager, just make sure you have useResultCache and/or useQueryCache set to true. If you want to use the user cache, just grab the service out of the container like so:

// Change default to the name of your instance
$cache = $container->get( 'aequasi_cache.instance.default' );
// Or
$cache = $container->get( 'aequasi_cache.default' );

Here is an example usage of the service:

$cache = $this->get( 'aequasi_cache.instance.default' );
$item = $cache->getItem('test');
if ($item->isHit()) {
	var_dump($item->get());
	
	return;
}

$cache->saveItem('test', $em->find('AcmeDemoBundle:User', 1), 3600);

Need Help?

Create an issue if you've found a bug, or ping me on twitter: @aequasi

cache-bundle's People

Contributors

aeyoll avatar alex-pex avatar bitdeli-chef avatar cdaguerre avatar cordoval avatar cryptiklemur avatar h4cc avatar jeroenvdgulik avatar nyholm avatar phobetor avatar scrutinizer-auto-fixer avatar volkan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cache-bundle's Issues

Memcached options

Is there a way to set memcached options?

The options array in the instances configuration is not defined to contain any values.

Persistant connexion never close

Experiencing a weird issue with cache-bundle.

Using cache-bundle with persistant:true on configuration, persistant connexion never close and memcached current_openned_connection number never stop increasing.

Session Cache seems not to work

I used your memcached bundle before and switched to the new cache-bundle. Unfortunatly it seems that the session caching doesn't work like before. It simply doesn't find the sessions in the memcache (we are using elasticcache)

Use other type of cache

Hi !

I want to try file cache, but i get this error :
file is not a valid cache type. If you are using a custom type, make sure to add your service.

And i see in services.yml there are many caches services: array, xcache, ...
But the config only accept : 'redis', 'file', 'memcached', 'apc'.

Is it possible to use these other services ?

Thanks for your help

disable memcache for one or two specific queries

Hello,

I've a great problem: on the one hand I really want and need speed thing up a little bit by using memcache in my symfony2 application. On the other hand I have at least one or two single queries I never want to be cached.

Any idea how to do that?

Clearing memcache from sf2 console command

Is it possible to add a command to clear memcache from CLI? I know I can do it with just memcache but it would be nice for our builds to clear routing and doctrine metadata cache without any special privileges to directly contact Memcached.

Session TTL is not used as shown in example configuration

The example configuration shows that the session TTL value is set as shown:

aequasi_cache:
    session:
        enabled: true
        instance: default
        prefix: "session_"
        ttl: 1800

However, the TTL value specified here is not used, instead the cookie_lifetime value is used from the Symfony framework session configuration.

Routing Caching with FOS Rest Bundle

If you use fos/rest bundle and using routing caching from aequasi memcache bundle, the bundle does not stores the http verb to cache.

you have two routes:

  • GET /user/profile
  • PUT /user/profile

If you send a PUT without routing caching enabled, it jumps in the right method. If you send a PUT with routing caching enabled, it jumps in getUserProfile instead of putUserProfile.

It would be better, if you also cache the http verb: e.g.: get_user_profile, put_user_profile

unable to setup without session

If you do not setup the session storage (e.g. because you want to store the data in the database like we do) the bundle cannot be setup properly:

ContextErrorException: Notice: Undefined index: instance in /home/benjamin/www/web/vendor/aequasi/cache-bundle/src/Aequasi/Bundle/CacheBundle/DependencyInjection/Compiler/SessionSupportCompilerPass.php line 42

Issue with using Symfony 2.0.1 version

I downloaded the latest version but I get this error
I am using Symfony 2.0.1

Call to undefined method Symfony\Component\Config\Definition\Builder\NodeBuilder::append()

symfoy3 support

Cant install this bundle on symfony3:

composer update
....
- aequasi/cache-bundle 3.0.2 requires symfony/symfony ~2.2 -> no matching package found.

Any plans to support symfony3 soon?
Or how can i make composor ignore the dependency?

PHP requirement ~5.3

If you want to use or test the bundle with php 7.x, composer will fail with the following error.

- aequasi/cache-bundle 3.0.2 requires php ~5.3 -> your PHP version (7.0.8) does not satisfy that requirement.

Wrong configuration setting for type

I just tested your cache bundl which looks great.
For dev and testing purpose, I need to use the file cache.

On the file Aequasi\Bundle\CacheBundle\DependencyInjection\Configuration.php on line 73 you're setting the available type option:
->values(array('redis', 'file', 'memcached', 'apc'))

After digging into your code, it appears the file option is not available.
Instead we should use php_file or file_system.

I found out that after looking on the services.yml file

It seems that there is other type possibility too:
array, memcache, win_cache, xcache and zend_data.

I didn't test them.

So to correct the issue, it seems the only required action is to update the availble option by setting:
->values(array('redis', 'php_file', 'file_system', 'memcached', 'apc'))
(and maybe more for the others)

Metadata and Memcached

It also appears that clearing the metadata cache doesn't work with memcached

To reproduce:

Create an entity and store cache in memcached
Edit / Add / Remove a column from the entity and attempt to perform a doctrine schema update

Missing the underlying interface of Symfony UrlMatcher

hi,

it seems your cache key generation is overlooking the underlying UrlMatching logic of symfony

protected function matchCollection($pathinfo, RouteCollection $routes)
    {
        foreach ($routes as $name => $route) {
            $compiledRoute = $route->compile();

            // check the static prefix of the URL first. Only use the more expensive preg_match when it matches
            if ('' !== $compiledRoute->getStaticPrefix() && 0 !== strpos($pathinfo, $compiledRoute->getStaticPrefix())) {
                continue;
            }

            if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
                continue;
            }

            $hostMatches = array();
            if ($compiledRoute->getHostRegex() && !preg_match($compiledRoute->getHostRegex(), $this->context->getHost(), $hostMatches)) {
                continue;
            }

            // check HTTP method requirement
            if ($req = $route->getRequirement('_method')) {
                // HEAD and GET are equivalent as per RFC
                if ('HEAD' === $method = $this->context->getMethod()) {
                    $method = 'GET';
                }

                if (!in_array($method, $req = explode('|', strtoupper($req)))) {
                    $this->allow = array_merge($this->allow, $req);

                    continue;
                }
            }

            $status = $this->handleRouteRequirements($pathinfo, $name, $route);

            if (self::ROUTE_MATCH === $status[0]) {
                return $status[1];
            }

            if (self::REQUIREMENT_MISMATCH === $status[0]) {
                continue;
            }

            return $this->getAttributes($route, $name, array_replace($matches, $hostMatches));
        }
    }

if two routes with same path_info is defined and has different Controller end-points Your cache implementation will always call the first match of the cache entry against the path but overlooks the rest of route matching logic in symfony.

public function match($pathInfo)
    {
        $key = 'route_' . $pathInfo;
        if ($this->cache->contains($key)) {
            return $this->cache->fetch($key);
        }

        $match = parent::match($pathInfo);
        $this->cache->save($key, $match, 60 * 60 * 24 * 7);

        return $match;
    }

at least $key should include minimal request method to overcome issue, however if there are complex routes defines with extra requirements other than request method then the cache key generation should take into account of all requirements of a route.

Multiple Memcached Instances

Anytime I attempt to create multiple memcached instances I am greeted my whitescreens of death.

It doesn't say in the documentation that I can't split things across multiple memcached clusters, so I'm just curious if this is expected behaviour?

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.