Hi Thomas,
On May 27, 2008, at 12:24 PM, Thomas Mortagne wrote:
  Hi Vincent,
 I already sent a mail (
http://markmail.org/message/euavqzjz53mxxkut)
 explaining the cache service -> cache components I planned/coded. 
Yes sorry I forgot about that mail :)
  You
 can find a first api and a complete oscache implementation at
 
http://jira.xwiki.org/jira/browse/XWIKI-2359. 
Haven't found the time to look at the patch yet. I thought it might be
easy if you explain it, which you did below.
  I designed this api looking to all places we used the
old cache
 service and all this used to support. Lets list here the main lines of
 it :
 1) What the new api already contains (see
 
http://jira.xwiki.org/jira/browse/XWIKI-2359) :
  1.1) First of all, there is two different component roles :
    * cache : create named cache that can be local or distributed
 caches depends on the implementation and its configuration. Typically
 used for documents cache.
    * local cache : create only and always local caches seems to be
 needed by some part of XWiki core like groovy, feed plugin and image
 plugin 
Could you explain why we need 2 cache roles?. Why not a single Cache
role but with different role hints?
Examples of hints:
* "local/LRU"
* "distributed/oscache"
* "memcached"
* "jbosscache/local"
etc.
or simply:
"local"
"distributed"
I'm not saying it's bad but it looks strange to have a method to
create local and distributed caches and another one to create local
caches only. It's not balanced and I think that reflects a problem in
the API.
Cannot we consider the fact that the cache is distributed or not a
configuration of the cache? That's unless the 2 cache interfaces are
different.
   That way we can set in the configuration that we want
memcached for
 normal cache and JBossCache for local cache for example.
  1.2) Factory create cache and take parameters like "capacity" 
I think it should maybe also take an EvictionPolicy. The capacity
could be a parameter of the EvictionPolicy. Some caches don't require
a "capacity" so I don't think the capacity should be in the method for
creating a cache.
   1.3) Cache contains :
    * get : get the value by key, can take a timing as parameter
 compared to the time the value was registered the last time 
Hmm... Not sure I like this timing too much. How do the oscache and
jbosscache do this?
     * set : modify or add a value to the cache
    * remove : remove a value from the cache 
How do you configure a cache?
   1.4) Cache can call listeners on add, delete,
update... 
By listeners do you mean the Observation component?
We definitely need to support the use case where a cache of documents
removes a given document when it's modified. I'd say that this should
be implemented using an EvictionPolicy implementation.
   1.5) Cache support generics
 This api support all you listed I think (except for the way the timed
 cache works). It is generally based on the old cache services concepts
 even all the names changes but the more I'm working with JBoss cache
 the more I think this api need some changes as JBoss cache and OSCache
 has very different way to create there caches. 
We should definitely not base our new API on the existing xwiki API.
Instead we should focus on the general needs we have and on the state
of the art about caching.
  2) Problems/not sure yet :
  2.1) old cache service provide methods taking maps of properties as
 parameters need by image plugin for example. 
Not sure I understand this.
  My problem here is that
 all existing cache frameworks like OSCache, JBoss etc... are very new
 to me and I'm not sure of what feature I can generalize in this map. I
 think of starting by taking all properties setted by image plugin and
 list them as XWiki Cache properties and translate them for each
 implementations. Capacity, name all Factory take as parameters should
 be included in a CacheConfiguration object. Some of theses properties
 can also be ignored by implementation in some cases.
  2.2) I think I need to change the way the timing works in this api
 as I did not find how to support it in JBoss yet. A more restrictive
 way and supported by JBoss would be to provided the limit time for the
 whole cache. I don"t really see a need for more. I'm thinking of
 introduce eviction algorithms concept like JBoss or cache4j do to
 replace the way restriction like capacity and timing are supported. 
Yep, see above.
  3) Other features the cache component could support
for XWiki needs
  3.1) for documents cache, Ludovic proposed the idea of something
 like a "meta cache" when we are using distributed cache: the idea is
 to only store the documents version in the distributed cache and store
 the reall document in a local cache. The local cache is synchronised
 with distributed cache based on the documents version:if it changed
 the document has to be reloaded from the database. This avoid the
 serialization/unserialization process of the whole document in the
 distributed cache. 
No comment on this yet. Haven't thought about it deeply enough...
  On Tue, May 27, 2008 at 10:43 AM, Vincent Massol
 <vincent(a)massol.net> wrote:
> Some more thoughts:
>
> 1) Actually we can probably use the google collections api for all
> our
> needs. For example it has
>
http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/commo…
>
> 2) I'm not sure the PhantomReference is correct. It would be useful
> if
> we wanted to save the AST on disk for example but I don't know if
> that
> would win us processing time or not. It may. Otherwise a
> SoftReference
> would be enough. The difference is that with PhantomeReference the
> JVM
> calls you before the item is reclaimed so you can do something with
> it
> before it's too late...
>
> 3) If we want to go in this direction we'll need to decide if we want
> to continue using only the Apache Collections fwk or if it's ok to
> use
> both google's and apache's.
>
> 4) Do you know of any existing cache framework that we could use
> directly? (I haven't researched this but you probably have). 
After more thought I don't think we need all of this and we should use
directly one of the cache frameworks and not redo it. So we should use
directly jbosscache or oscache. The different strategies should
probably be implemented as EvictionPolicy.
  Plexus cache api
 (
http://plexus.codehaus.org/plexus-components/plexus-cache/plexus-cache-api/…
 )
 and some implementations. The problem is that the api is not very
 generic and the way it is designed you need to know the implementation
 you use to correctly configure the cache to create. But maybe I take
 it the wrong way and should not try to force the whole XWiki Platform
 to be able to use any cache component implementation...
 Except for the plexus one I did not found a real "framework of cache
 framework" but I did not search weeks for it... 
We shouldn't use Plexus IMO. We need our own Caching API. It's only
the implementation that we shouldn't do and instead wrap jbosscache,
oscache, etc. In addition the plexus cache is not something mature
enough compared to jbosscache, oscache, etc.
Thanks
-Vincent
 > On May 27, 2008, at 10:35 AM, Vincent Massol
wrote:
>
>> Hi Thomas,
>>
>> I know you're working on the new cache component (btw would be
>> nice if
>> you could send an email with your planned architecture/api so that
>> it
>> can be reviewed - like show the APIs) so I thought I should give you
>> some needs/ideas I have on this topic.
>>
>> * We need several types of local caches. I can see at least the
>> following types:
>> - a timed cache. I need this for example to cache macros
>> - a cache with a fixed given capacity and expiring the oldest
>> entries
>> (not really sure where we need this right now but it looks common
>> enough)
>> - a cache with a fixed given capacity and expiring the least
>> accessed
>> entries (not really sure where we need this right now but it looks
>> common enough)
>> - a cache with unlimited capacity and bound only by the memory
>> available. The way to implement this is using PhantomReference.
>> Basically it's the JVM that calls back the reference to tell it it
>> needs memory. I was told that the new google collections api have
>> some
>> code that do this (I think FinalizablePhantomReference). This
>> cache is
>> the one I would use to save wiki pages' AST in memory.
>>
>> Of course we shouldn't implement anything ourselves and we should
>> use
>> existing framework(s) underneath our own API for the Cache API.
>>
>> WDYT?
>>
>> Links:
>> * 
http://www.realjenius.com/node/377
>> *
http://www.javalobby.org/forums/thread.jspa?threadID=16520&messageID=91…
>>
>> Thanks
>> -Vincent