8000 [2.1] Unify cache mechanisms · Issue #1513 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[2.1] Unify cache mechanisms #1513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vicb opened this issue Jul 4, 2011 · 29 comments
Closed

[2.1] Unify cache mechanisms #1513

vicb opened this issue Jul 4, 2011 · 29 comments

Comments

@vicb
Copy link
Contributor
vicb commented Jul 4, 2011

The doctrine bundle, the validator and the annotation reader all support caching.

The doctrine bundle supports memcache, apc, array and xcache.

The annotations reader supports file and any mechanism that implements Doctrine\Common\Cache\Cache by providing a service in the configuration.

The validator component only supports apc.

It would be great to be able to define some cache providers in the framework configuration and use them from the configuration of those 3 components.
That would require changing the configuration of the doctrine bundle and the annotation reader and implement a ClassMetadataFactory that would use an instance of Doctrine\Common\Cache\Cache.

@dlsniper
Copy link
Contributor
dlsniper commented Jul 4, 2011

It would also be very good to have those caching mechanisms available for use in the applications themselves as it would make them a very convenient way

@Seldaek
Copy link
Member
Seldaek commented Jul 4, 2011

👍 This kind of mess with everyone using their own caching providers is what you find in Drupal plugins, each having their own wheel, and it's very unpleasant to work with.

@winzou
Copy link
winzou commented Jul 4, 2011

+1. Thus people won't have to make already-exist-wheel bundles, such as mine https://github.com/winzou/CacheBundle (bridge to use Doctrine Cache)

@dlsniper
Copy link
Contributor
dlsniper commented Jul 5, 2011

@winzou: Maybe your bundle could be included in the standard distribution of Symfony2 at least? I don't know if making Doctrine use your caching approach could be done easily but for 2.0 release it would be better that having no cache at all. I was actually about to start to work on something similar to your bundle when I've seen this comment.

@stof
Copy link
Member
stof commented Jul 5, 2011

This bundle cannot be used for Doctrine (or any other places relying on the Doctrine Common implementation) as the cache implementations don't implement the Doctrine\Common\Cache\Cache interface.

@rande
Copy link
Contributor
rande commented Sep 4, 2011

FYI : the SonataPageBundle provides some cache handlers : https://github.com/sonata-project/SonataPageBundle/tree/master/Cache and their dedicated invalidation mechanism.

@stof
Copy link
Member
stof commented Sep 4, 2011

IMO, it would be better to use the Doctrine\Common\Cache implementation as Doctrine Common is already a dependency for the annotations.

@Seldaek
Copy link
Member
Seldaek commented Sep 4, 2011

IMO it would be better if we had a cache interface in Cache namespace or something, à la PHPCR, that everyone -including doctrine- would extend from or just use as is. We can't build standards on top of the Doctrine namespace.

@rande
Copy link
Contributor
rande commented Sep 4, 2011

@Seldaek
Copy link
Member
Seldaek commented Sep 4, 2011

Yes, that's a good start, for Symfony, but I'd hope for a world where every PHP lib could require 'cache_interface', and 'cache', and where any cache provider library would provide 'cache' and also require 'cache_interface. That should allow any library to use a cache chosen by the user (by requiring any lib that provides cache). I hope to do that with composer.

@lsmith77
Copy link
Contributor

i agree .. i would like to see https://github.com/liip/LiipDoctrineCacheBundle moved to the Doctrine organization.
furthermore we should have a way to configure memcache(d) services (either in the just mentioned bundle or inside the framework bundle) because right now we have the same configuration logic for memcache(d) all over the place

@vicb
Copy link
Contributor Author
vicb commented Jan 15, 2012

I am not sure if the Doctrine team should be responsible for unifying the cache across Symfony. This should rather be handled in Symfony and used by Doctrine.

  • It is outside of the scope of the Doctrine team to unify the cache mechanisms in Symfony,
  • We could add more functionality that what is strictly required by Doctrine,
  • Caching is important and should really be part of the framework.

@stof
Copy link
Member
stof commented Jan 15, 2012

@vicb Symfony already depends on Doctrine Common for the annotation part so we could rely on it for the caching part.

Otherwise, we would have a yet-to-be-written Symfony cache and a Doctrine Cache along it for Doctrine. And this would not be a unified cache :)

@vicb
Copy link
Contributor Author
vicb commented Jan 15, 2012

@stof the idea would be to use doctrine common for the low level cache drivers but I still think the bundle should be handled by Sf and could provides more functionality that what is strictly needed by Doctrine.

(But yes we should also probably consider having a "Symfony cache" with some kind of adaptors for Doctrine during the design phase)

@winzou
Copy link
winzou commented Jan 26, 2012

Where are we on this issue? I believe this is an important point to deal for the 2.1.

@vicb
Copy link
Contributor Author
vicb commented Jan 26, 2012

On my side I haven't made of lot of progress (except a few PRs against doctrine common)

My vision ATM:

  • Having a CacheBundle with some CacheFactories (a la SecurityBundle) which would allow creating cache services,
  • Update others bundles (doctrine, framework - validation & annotation, ...) to make use of those services.

Why cache factories ?
It might help for cache services relying on a client / server mechanism (i.e. memcache). More generally it would help abstracting the configuration difference amongst cache drivers.

Should we use the drivers from Doctrine2 ?
That might be a good starting point but once we have something running, we should may be consider creating a Cache component. Doctrine2 has specific needs that might not fit with a generic solution.
If we stop using the drivers from Doctrine then we should develop some adapters (which should be simple).

The bundle from Liip is probably a good starting point. Ideally in the config id should server which could be either a service or an array (ip, port, timeout, ...) - your or any other bundle might be good as well but I haven't had time to look at them.

That is my POV.

@vicb
Copy link
Contributor Author
vicb commented Jan 26, 2012

@winzou May be the more important is that somebody start something, what about you ?

@lsmith77
Copy link
Contributor

I very much like that plan and I am totally ok with retiring LiipDoctrineCacheBundle once this is all in place. Especially I share the sentiment that we need factories (even for just Memcache(d) instances) so that we can then use these in any other bundles instead of having to duplicate the code to build the instances all over the place as we do now.

@pulzarraider
Copy link
Contributor

Maybe we can create a Cache Component instead of bundle. The Cache component will be independent and usable in any other non-Symfony2 project as other Symfony Components are now.

@dlsniper
Copy link
Contributor

+1 for @pulzarraider idea.

Having something like a Cache component that would also allow for adding new types of caches would be great.

I'm thinking to start with it should allow for these types of cache formats:

  • file
  • apc/xcache
  • memcache(d)

It should contain the basic methods for all the classes:
::add($key, $value, $timeout)
::has($key)
::get($key)
::remove($key)
::removeExpired()
::getAllKeys()

Maybe also it should have some sort of console command interface so that you can run all the above functions from cli directly.

I'm not sure how to exactly start on this but if you all agree with the above I could give it a try next week and possibly make a PR by the end of 5th February.

@vicb
Copy link
Contributor Author
vicb commented Jan 29, 2012

@pulzarraider @dlsniper what about using doctrine common for now and focus on the bundle ? (see my previous msg)

@dlsniper
Copy link
Contributor

@vicb I was taking into consideration this comment: #1513 (comment)

@vicb
Copy link
Contributor Author
vicb commented Jan 29, 2012

Changing a namespace is not a problem, re-develop a working solution is a waste of time.

@lstrojny
Copy link
Contributor

I know, I’m gonna be beaten but why not use Zend\Cache\Manager? It’s supports a wide variety of adapters, has support for tagging and we would only need a few bridges implementing package specific interfaces (e.g. for Doctrine).

@rande
Copy link
Contributor
rande commented Jan 29, 2012

I will be happy to merge/refactor the SonataPageBundle's cache handler, however there is a missing feature in the current thread : contextual information.

A cache can have :

  • an id (the key)
  • a value (the cached data)
  • some contextual informations (help to invalidate the cache)

I guess the LiipDoctrineCacheBundle and SonataPageBundle's cache code can be merge/refactored to match our need.

@mvrhov
Copy link
mvrhov commented Jan 29, 2012

The question with Zend\Cache\Manager is how decoupled it really is.
Quick glance show that it pulls in the following namespaces:
Zend\Filter
Zend\Config
Zend\Log

@beberlei
Copy link
Contributor

Imho Symfony should provide its own Cache interface in the Components (HttpKernel?), like with logging and have no implementation on its own.

If its looking like the Doctrine interface or even simpler then we could easily have a Doctrine wrapper in FrameworkBundle, as that already depends on Doctrine Common anyways. We could then move LiipCacheControlBundle into FrameworkBundle.

It makes much more sense in the core than in Doctrine org. Only this way we get it unified.

@fabpot
Copy link
Member
fabpot commented Mar 23, 2013

@fabpot
Copy link
Member
fabpot commented Aug 24, 2013

Closing as we will not do anything before FIG agree on a cache interface that we can leverage.

@fabpot fabpot closed this as completed Aug 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

0