[TYPO3-mvc] Persistence object caching

Chetan Thapliyal chetan.thapliyal at aoemedia.de
Fri May 20 10:05:54 CEST 2011


On 20.05.2011 02:12, Franz Koch wrote:
> Hey,
>
>> I just faced a weird problem with caching of persistence objects in
>> extbase. When an object is queried for the first time, extbase keeps a
>> copy of it in memory. That means when the same object is queried again
>> in the same PHP session extbase returns the copy kept in memory rather
>> than making a new one. This has some implications. If the object's data
>> is modified in database by some other PHP session triggered after the
>> first query then the changes won't reflect in existing PHP sessions.
>> This is exactly what happened with me.
>>
>> While debugging I noted that extbase do fetch the data from database for
>> every query but doesn't use it if there already exists a copy of the
>> object in memory.
>
> That can only happen if you modify the data of the object outside of
> Extbase (directly via SQL). If that's the case you should remove the
> object from the identityMap of the persistenceLayer in order to get a
> new version of it from the repository. But note that any already
> existing copy of the object will still hold the old data though (there
> is no instant update).
>
> May I ask why there might be changes applied via RAW sql the object
> itself doesn't know about during it's lifecycle?
>

Hi Franz,

Long story in short. I encountered this issue while doing database 
testing using PHPUnit. I was restoring the database to an initial state 
after each test. It was okay as long as I was just reading the data. But 
once objects were modified I was not able to get them with pristine 
state no matter how many times I was dropping & recreating the database 
or destroying and recreating the repository instance.

Using identityMap of the persistenceLayer to remove the object is 
possible but is it really the only solution. What if I modify 50 
different objects during test. At the end of each test I would have to 
select all of those 50 objects & manually delete them from cache. For 
some small simple tests its overkill. I would be writing more code for 
clean-up than testing.


-- 
Chetan Thapliyal
System Developer

e-Mail: chetan.thapliyal at aoemedia.de
Web: http://www.aoemedia.de/


More information about the TYPO3-project-typo3v4mvc mailing list