KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > cache > impl > SimpleCacheService


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.services.cache.impl;
6
7 import java.util.Collection JavaDoc;
8 import java.util.HashMap JavaDoc ;
9
10 import org.exoplatform.services.cache.CacheService;
11 import org.exoplatform.services.cache.ExoCache;
12 import org.exoplatform.services.cache.SimpleExoCache;
13 import org.picocontainer.Startable ;
14 /**
15  * Created by The eXo Platform SARL .
16  * Author : Tuan Nguyen
17  * tuan08@users.sourceforge.net
18  * Sat, Sep 13, 2003 @
19  * Time: 1:12:22 PM
20  */

21 public class SimpleCacheService implements CacheService, Startable {
22   private HashMap JavaDoc cacheMap_ ;
23   
24   public SimpleCacheService() {
25     cacheMap_ = new HashMap JavaDoc() ;
26   }
27   
28   public ExoCache getCacheInstance(String JavaDoc region) throws Exception JavaDoc {
29     if( region == null || region.length() == 0) {
30       throw new Exception JavaDoc ("region cannot be empty");
31     }
32     ExoCache cache = (ExoCache) cacheMap_.get(region) ;
33     if (cache == null) {
34       synchronized (cacheMap_) {
35         cache = new SimpleExoCache(region, 100) ;
36         cacheMap_.put(region, cache) ;
37       }
38     }
39     return cache ;
40   }
41   
42   public Collection JavaDoc getAllCacheInstances() throws Exception JavaDoc {
43     return cacheMap_.values() ;
44   }
45   
46   public void start() { }
47   public void stop() {}
48 }
49
50
Popular Tags