Last week I discovered a flaw in the EntityListCache implementation:
http://mail-archives.apache.org/mod_mbox/incubator-ofbiz-dev/201304.mbox/%3c516ac7b4.2020...@sandglass-software.com%3E
To summarize: Entity conditions that are cached become stale when any
member of the cached list is changed - making the cache contents
invalid. In addition, GenericValues in the cached list are mutable -
which is inconsistent with the primary key cache, where GenericValues
from the cache are immutable.
I would like to fix this, but I think we should discuss it first.
One change would be to make the list member GenericValues immutable.
This will make the GenericValues retrieved from the entity list cache
consistent with the GenericValues retrieved from the primary key cache,
but it won't prevent an invalid cache (because the list member
GenericValue can be cloned and modified). Also, this change will likely
break a lot of code, because it is common to retrieve a list of
GenericValues from the cache and then make changes to the list members.
We could create a "transitional" GenericValue that would warn developers
when they modify a cached list member, and then switch to an immutable
GenericValue some time in the future.
To fix the stale cache problem, the cache instance can be made a
GenericValue listener in all of its list members - so any time a list
member is modified the cache will be cleared. This will keep the cache
valid, but there might be a performance hit. I'm open to other solutions
to this problem.
Any thoughts?
-Adrian