Doctrine2 Caching Updated Items

I have a problem with the doctrine. I like caching, but if I update Entity and flush, should doctrine2 clear the cache? Otherwise, the cache is used very little for me, since this project has a lot of interaction, and I would literally always disable the cache for each request. Users would not see their interactions if the cache always showed them the old cached version.

Is there any way to do this?

+5
source share
3 answers

This is consistent with the Doctrine2 documentation on how to clear the cache. I'm not even sure if this is what you want, but I think this is something to try.

The Doctrine2 cache driver has different levels of deletion of cached entries.

, , ,

, , :

$deleted = $cacheDriver->deleteAll();

:

$deleted = $cacheDriver->deleteByPrefix('users_');

, Doctrine2 , .

: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/caching.html#deleting

, . , .

, :

$config = $em->getConfiguration(); //Get an instance of the configuration
$queryCacheDriver = $config->getQueryCacheImpl(); //Gets Query Cache Driver
$metadataCacheDriver = $config->getMetadataCacheImpl(); //You probably don't need this one unless the schema changed

, , cacheDriver - . . .

, , - , , . , , , , . , , . , , .

: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/caching.html#result-cache

$query = $em->createQuery('select u from \Entities\User u');
$query->useResultCache(false); //Don't use query cache on this query
$results = $query->getResult();
+1

()? , .

$entity = new Entity();
$em->persist($entity);
$em->flush();
$em->refresh($entity);

, Entity, $em- > flush().

( , ), , . → http://www.doctrine-project.org/jira/secure/Dashboard.jspa

+3

Doctrine2 , deleteByPrefix, Doctrine1 - (3 ) , .

The page http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/caching.html#deleting is deprecated (the next version of doctrine2 will see that these methods are deleted). The only thing you can do now is to manually manage the cache: find the identifier and delete it manually after each update.

A more advanced doctrine caching is WIP: https://github.com/doctrine/doctrine2/pull/580 .

+3
source

All Articles