I have received permission to contribute my hibernate oscache provider patch.  Here is 
the unified patch, the whole classes are attached:

Index: OSCache.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/cache/OSCache.java,v
retrieving revision 1.6
diff -u -r1.6 OSCache.java
--- OSCache.java        4 Jun 2004 05:43:45 -0000       1.6
+++ OSCache.java        27 Oct 2004 16:26:30 -0000
@@ -1,8 +1,12 @@
 //$Id: OSCache.java,v 1.6 2004/06/04 05:43:45 steveebersole Exp $
 package net.sf.hibernate.cache;
 
+import java.util.Properties;
+
+import net.sf.hibernate.util.PropertiesHelper;
 import net.sf.hibernate.util.StringHelper;
 
+import com.opensymphony.oscache.base.Config;
 import com.opensymphony.oscache.base.NeedsRefreshException;
 import com.opensymphony.oscache.general.GeneralCacheAdministrator;
 
@@ -10,14 +14,28 @@
  * @author <a href="mailto:[EMAIL PROTECTED]">Mathias Bogaert</a>
  */
 public class OSCache implements Cache {
+    
+    /** 
+     * The <tt>OSCache</tt> cache capacity property suffix. 
+     */
+    public static final String OSCACHE_CAPACITY = "cache.capacity";
+
+    private static final Properties OSCACHE_PROPERTIES = new Config().getProperties();
        /** 
         * The OSCache 2.0 cache administrator. 
         */
-       private GeneralCacheAdministrator cache = new GeneralCacheAdministrator();
+       private static GeneralCacheAdministrator cache = new 
GeneralCacheAdministrator();
+
+    private static Integer capacity = PropertiesHelper.getInteger(OSCACHE_CAPACITY, 
OSCACHE_PROPERTIES);
 
+    static {
+        if (capacity != null) cache.setCacheCapacity(capacity.intValue());
+    }
+    
        private final int refreshPeriod;
        private final String cron;
        private final String regionName;
+    private final String[] regionGroups;
        
        private String toString(Object key) {
                return String.valueOf(key) + StringHelper.DOT + regionName;
@@ -27,10 +45,7 @@
                this.refreshPeriod = refreshPeriod;
                this.cron = cron;
                this.regionName = region;
-       }
-
-       public void setCacheCapacity(int cacheCapacity) {
-               cache.setCacheCapacity(cacheCapacity);
+        this.regionGroups = new String[] {region};
        }
 
        public Object get(Object key) throws CacheException {
@@ -44,7 +59,7 @@
        }
 
        public void put(Object key, Object value) throws CacheException {
-               cache.putInCache( toString(key), value );
+               cache.putInCache( toString(key), value, regionGroups );
        }
 
        public void remove(Object key) throws CacheException {
@@ -52,11 +67,13 @@
        }
 
        public void clear() throws CacheException {
-               cache.flushAll();
+               cache.flushGroup(regionName);
        }
 
        public void destroy() throws CacheException {
-               cache.destroy();
+               synchronized (cache) {
+                   cache.destroy();
+        }
        }
 
        public void lock(Object key) throws CacheException {
Index: OSCacheProvider.java
===================================================================
RCS file: 
/cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/cache/OSCacheProvider.java,v
retrieving revision 1.6
diff -u -r1.6 OSCacheProvider.java
--- OSCacheProvider.java        4 Jun 2004 05:43:45 -0000       1.6
+++ OSCacheProvider.java        27 Oct 2004 16:26:30 -0000
@@ -25,11 +25,7 @@
         * The <tt>OSCache</tt> CRON expression property suffix. 
         */
        public static final String OSCACHE_CRON = "cron";
-       /** 
-        * The <tt>OSCache</tt> cache capacity property suffix. 
-        */
-       public static final String OSCACHE_CAPACITY = "capacity";
-
+       
        private static final Properties OSCACHE_PROPERTIES = new 
Config().getProperties();
 
        /**
@@ -51,13 +47,8 @@
                );
                String cron = OSCACHE_PROPERTIES.getProperty( 
StringHelper.qualify(region, OSCACHE_CRON) );
 
-               // construct the cache
-               final OSCache cache = new OSCache(refreshPeriod, cron, region);
-               
-               Integer capacity = PropertiesHelper.getInteger( 
StringHelper.qualify(region, OSCACHE_CAPACITY), OSCACHE_PROPERTIES);
-               if ( capacity!=null ) cache.setCacheCapacity( capacity.intValue() );
-               
-               return cache;
+               // construct the cache        
+        return new OSCache(refreshPeriod, cron, region);
        }
 
        public long nextTimestamp() {





> -----Original Message-----
> From: Stefán Baxter [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, October 26, 2004 4:40 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [Opensymphony-oscache] RE: oscache and hibernate
> 
> Hi,
> 
> I have been using oscache for the past three years but we have recently
> added hibernate to our project. It's working fine with oscache but the
> multiple caches look strange even though they seem to work. It would be
> great to gain access to your modifications.
> 
> Best regards,
>   -Stefan
> 
> March, Andres wrote:
> 
> >Please keep this on the list, so other people may be enlightened/annoyed
> >by our thread.  Also, I don't mind but there is really no need to send
> >to me directly since I monitor the oscache and hibernate lists closely.
> >
> >full disclosure: I have been contributing to oscache and am trying to
> >push the 2.1 out the door now.
> >
> >You can see most of my thoughts about hibernate, jbosscache, and oscache
> >on the mailinglists and forums.  But I really like hibernate but am not
> >impressed by their team's willingness to support 2.1 and/or let other
> >people help do it for them.  I like oscache and like you found there is
> >really no alternative for clustered invalidation.  That does not mean
> >oscache is without issues but it does the job.  I am looking forward to
> >refining the code, adding more functionality, and fixing any bugs (none
> >impact me at the moment).
> >
> >We have just gone into beta with 50,000 users and will be ramping up to
> >hundreds of thousands once we go live
> >(http://eq2players-beta.station.sony.com).  Invalidation is just we
> >needed and it works perfectly (for us).  The only slightly minor
> >annoyance is the way hibernate need to evict every object individually
> >and cannot do an entire object graph.  I believe with replication this
> >would not be so much of a problem, since everything would stay up to
> >date.  But in the case of out-of-system updates the issue would remain.
> >This means custom code for evicting objects when you need to the scope
> >of which depends on your object model.  And remember there are separate
> >caches for collection references and query caches too, if you use them.
> >
> >But all in all we're pretty happy.
> >
> >As for as the hibernate oscache provider code.  I would be happy to
> >donate it to the community.  But since the hibernate team declined my
> >offer I have not asked for permission from SOE to donate it.  If you
> >would like to have it, I think I would rather set up an official fork
> >for hibernate that everyone could have access to since we have other
> >changes as well.  But the change was easy.  I basically just changed the
> >provider to only create one cache for the application since that is the
> >way oscache is intended to be used.  Instead of creating a cache per
> >region, I use groups to be able to flush a region at a time.  I can
> >explain more if you like but for now my fingers are tired and my company
> >pays me to do real work.
> >
> >
> >
> >>-----Original Message-----
> >>From: Andrew Houghton [mailto:[EMAIL PROTECTED]
> >>Sent: Tuesday, October 26, 2004 2:35 PM
> >>To: March, Andres
> >>Subject: oscache and hibernate
> >>
> >>Andres --
> >>
> >>I'm in the process of evaluating hibernate, using oscache for our
> >>distributed cacheing.  I saw your messages to the oscache mailing list
> >>and thought I'd write.
> >>
> >>First, I'd love to know what changes you made to the hibernate
> >>
> >>
> >provider
> >
> >
> >>-- I was shocked at the number of sockets being opened, which is what
> >>led me to your posts.
> >>
> >>Second, you're much farther along this process than I; how are your
> >>experiences with hibernate in general, and oscache in particular?
> >>
> >>
> >None
> >
> >
> >>of the other distributed caches look like they're what I'm looking for
> >>-- the jboss cache is replicated, which is huge, and unnecessary,
> >>overhead for what we're doing, and swarmcache seems to be a dead
> >>project.
> >>
> >>In any case, I'm hoping to learn from your experience.
> >>
> >>Thanks,
> >>
> >>Andrew
> >>
> >>
> >>--
> >>Andrew Houghton <[EMAIL PROTECTED]>
> >>
> >>
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: [EMAIL PROTECTED]
> >For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

Attachment: OSCache.java
Description: OSCache.java

Attachment: OSCacheProvider.java
Description: OSCacheProvider.java

Reply via email to