Conversation
|
Hello, thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link: |
lib/Doctrine/ORM/Cache/Region.php
Outdated
There was a problem hiding this comment.
Why countable? Most caches cannot know the number of entries.
|
So far it looks awesome specficially that it doesn't affect the code path of the current implementation of UnitOfWork much. It would be really awesome if we could keep it that way. With regard to the changes in the persisters we might need to employ a strategy pattern to get this working better. Think of the getEntityPersister() method detecting which code strategy to inject into the persister. I want to avoid cluttering the persisters even more, they already decide on so many different configurations. Regarding the implementation I made comments on the cache, the mapEntityKeys() implementation is not good the way it is. How will locking of items work? Can you explain? It seems to be a critical thing and i don't see how it can be implemented. Java has some pretty powerful caches. Otherwise keep up the good work, and try not affecting the current code paths too much ;) |
|
@FabioBatSilva just thinking - is it possible to refactor the persisters from inheritance into composition? The inherited code is either SQL Building, or update/insert related. By splitting the persisters API up in more single responsibilities it might be easier to introduce caching in a clean way. Currently just for by id queries its rather simple, i suppose the persisters require much more changes for the other caches. |
lib/Doctrine/ORM/Cache.php
Outdated
There was a problem hiding this comment.
The typehint is wrong. It should either be the ClassMetadata interface from Common or ClassMetadataInfo (which implements all the logic in the ORM and is the parent of ClassMetadata for BC reasons)
|
@stof sorry to bark in, but we should focus code reviews on the functional level for now, this PR will take another 1-2 months to get stable and will be very tricky. It would be much easier to follow in that period if the comments were related to the implementation only so long. |
If i got it corectly Hibernate suport 2 types of concurrently managed data. read/write
Transactional -> (This one we CAN NOT implement.)
|
Seems good.. |
|
Does anyone know when this second level cache would be released? I was looking to implement something like this myself, especially because just result caching collections in 2.3 causes duplication in cache (too much memory)/outdated objects(inconvenient for users), and this second level cache implemntation seems to solve all those problems. Not sure if I should wait for upgrade (depends on how long before 2.5) |
|
Wow !! 71 Commits, 141 Files Changed.. I'm going to rebase and reopen this PR.. |
|
I don't get why you didn't just force-push... :) |
|
Very nice work!! |
|
@skafandri this already got into 2.5 branch (master) as of #808 |
|
Awesome! Many thanks! |
|
Hi, awesome work. I'm using ZF2 + doctrine currently. Could you please tell me how to enable this feature using configuration files? I use module.config.php to configure my entitymanager. Followed the documentation at http://doctrine-orm.readthedocs.org/en/latest/reference/second-level-cache.html but it does not have an example of how to pass the setting as a configuration option. I've tried putting it in the module.config.php in the doctrine=>configuration=>orm_default section as second_level_cache_enabled, but that does not work. Thanks. Cheers. |
|
@jarrettj I think you have to wait for this pr to be merged. |
|
@jarrettj in your entity manager config add: |
|
@skafandri have you actually got it to work in zend framework 2 + doctrine? I tried adding your options to module.config.php: Sorry for being dumb! No luck. My errors: Thanks. Cheers. |
|
@jarrettj He is talking about entity manager config. If you want to use it with zf2 module you have definitely wait for doctrine/DoctrineORMModule#295. |
|
Cool @FabianKoestring thanks! Then I'll patiently wait. :) |
|
Well, the waiting is over @bakura10 thanks for merging 2nd level cache into doctrine-orm-module. Added the following to module.config.php: And updated my composer.json: Hope that helps anyone else using ZF2 + doctrine. |
|
How would you set the file lock region directory to use the READ_WRITE mode? |
|
Setting the cache usage is done in your entity with annotations. Setting the second level cache is a two steps process : you mark your entity as cacheable with an optional region, and you configure the region through arrays |
|
@bakura10 All my entities have the Cache("READ_WRITE") annotation. But that does not work. It throws an error saying: The configuration documentation does not have any details on how to set this file lock region directory. If I use Cache("NONSTRICT_READ_WRITE") annotation, it works. But it does not cache relationships. Even when adding the Cache("NONSTRICT_READ_WRITE") annotation to associations and their target entity classes. Thought if I tried Cache("READ_WRITE") instead, the entity association would maybe work. |
|
Looks like an option is missing. I'll have a look at this after lunch |
|
Cool man :) |
|
@jarrettj , addressed by doctrine/DoctrineORMModule#378 Thanks for reporting! |
|
Only happy to help dude! Will have a look later. |
|
File lock directory option works! :) Associations still don't work though. :( I'll have a closer look tomorrow though. Thanks for the help so far though guys. |
|
All jesus, all working! Just did a restart of memcache. This is Freakin Awesome! :) |
|
Good to know! :) Second Level Cache is indeed an awesome feature! |
Hi guys. :)
After a look into some implementations I end up with the following solution for the second level cache..
There is lot of work todo before merge it, but i'd like to get your thoughts before i go any further on this approach.
I hope my drafts are good enough to explain the idea :
Cache strategies
classes / interfaces
Defines a contract for accessing a entity/collection data cache. (Doesn’t employ any locks)
Defines contract for concurrently managed data region. (Locks the data before update/delete.)
Defines entity / collection key to be stored in the cache region.
Build cache entries and rebuild entities/colection from cache
Factory from second level cache components
Collection Caching
The most common use case is to cache entities. But we can also cache relationships.
A “collection cache” caches the primary keys of entities that are members of a collection (OneToMany/ManyToMany).
and each element will be cached into its region.
Only identifiers will be cached for collection. When a collection is read from the second level cache it will create proxies based on the cached identifiers, if the application needs to access an element, Doctrine will go to the cache to load the element data.
Query Cache
The query cache does not cache the state of the actual entities in the result set;
it caches only identifier values for an individual query.
So the query cache should always be used in conjunction with the second-level cache.
Query Cache validation
OPERATIONS
INSERT :
UPDATE :
DELETE :
USAGE :
TODO :