[TYPO3-mvc] Flush persistence cache

Franz Koch typo3.RemoveForMessage at elements-net.de
Wed Jul 7 14:38:26 CEST 2010


Hi,

> lets say I'm fetching an object from a repository like this. $myFirstField =
> $fieldRepository->findOneByUid(4711);
>
> Now I'm changing some attributes in the resulting object which are
> intentionally excluded from being persisted to DB.
>
> Now I'm fetching the same DB record again:
>
> $mySecondField = $fieldRepository->findOneByUid(4711);
>
> The resulting object $mySecondField still has the changed non-DB-attributes
> from $myFirstField. However I want $mySecondField to be read from DB again.
> So my assumpotion is, that Extbase caches objects once they've been
> registered for the first time. Is there a way to get rid of all cached
> instances?

well, the very same object can only exist once at a time. If you fetch a 
object, it's loaded into the persistence layer so that it can be checked 
for changes to persist after the request was processed. If you fetch the 
same object (uid) again and it already exists in the persistence layer, 
it's fetched from there which will speed things up.

Now, if you have to modify the object, but don't want those changes to 
be persisted etc. simply work with a clone.

// this object is registered in the persistence layer
$myObject = $myRepository->findOneByid(123);

// now create a clone. The clone will have the same data as the original 
one, but will not get persisted, so modify this object instead of the 
original one
$myTempObject = clone($myObject);
$myTempObject->setWhatever('fooBar');
// do something more with it and finally remove it from RAM
unset($myTempObject);


-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list