[Building Sakai] cache automatically updates itself?

Aaron Zeckoski azeckoski at unicon.net
Sun May 30 00:37:10 PDT 2010


It's a little odd to double cache things but I doubt that will hurt
the system too badly. It will just use up more memory.

Without seeing the code, I can only guess but it sounds like maybe you
are placing an object into the cache and then updating the fields on
that same object. Since the memory service just uses ehcache
underneath and that stores its cached objects in a type of
ConcurrentHashMap it means any updates to the object would be
reflected in the cache as well (regardless of any explicit cache
update command you might have issued).
The same thing is true of hibernate objects which are updated except
that those updates are written into the database (despite not issuing
a save or update command). They are both artifacts of the object
oriented structure of Java (though in the case of hibernate it is
because it puts a double proxy on all hibernate objects).

Hope that is helpful.
:-)
-AZ



On Sun, May 30, 2010 at 12:02 AM, Steve Swinsburg
<steve.swinsburg at gmail.com> wrote:
> They are hibernate objects for persistence, but I am putting them into a
> MemoryService cache.
> cheers.
>
> On Sat, May 29, 2010 at 6:02 PM, Aaron Zeckoski <azeckoski at unicon.net>
> wrote:
>>
>> Are these hibernate objects and are you talking about the hibernate
>> cache or is this simply an object you are placing into the in-memory
>> cache in the memory service?
>>
>> -AZ
>>
>>
>> On Sat, May 29, 2010 at 12:13 AM, Steve Swinsburg
>> <steve.swinsburg at gmail.com> wrote:
>> > Hi all,
>> >
>> > I have a cache in my app that caches objects loaded from the database so
>> > that subsequent requests use the cached version and don't hit the database
>> > again.
>> >
>> > On one of my pages I allow a user to update their own version of the
>> > object and it is saved to the database. What I am seeing however, is that
>> > this change is also reflected in the cached version, ie they are kept in
>> > sync. Is this normal behaviour? I haven't specifically coded for updates to
>> > be readded to the cache, I was just testing and noticed this was happening
>> > anyway.  I am not sure if it's expected behaviour so will explicitly update
>> > the cache with the updated verison when it's saved.
>> >
>> > Some pseudocode of what I have at the moment:
>> >
>> > getRecord(userId) {
>> >
>> >   check cache
>> >   if exists in cache, returned cached version
>> >
>> >   if not get from db and add to cache for future lookups
>> > }
>> >
>> > updateRecord(object) {
>> >   save object to db
>> > }
>> >
>> > So no explicit cache update in the updateRecord method, but it's
>> > happening anyway.
>> >
>> > Any input on the Cache/MemoryService appreciated.
>> >
>> > cheers,
>> > Steve
>> > _______________________________________________
>> > sakai-dev mailing list
>> > sakai-dev at collab.sakaiproject.org
>> > http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>> >
>> > TO UNSUBSCRIBE: send email to
>> > sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of
>> > "unsubscribe"
>> >
>>
>>
>>
>> --
>> Aaron Zeckoski - Software Engineer - http://tinyurl.com/azprofile
>
>



-- 
Aaron Zeckoski - Software Engineer - http://tinyurl.com/azprofile


More information about the sakai-dev mailing list