I've attached a test case, where this unfortunately doesn't happen. I based this test case largely on Carsten Ziegeler's JCS code within Cocoon, so it is possible that there are errors in it ;-)
The test case creates a predefined number of items (strings) which it stores in the cache. On the second run, a test method should find the files written to the cache, but doesn't.
Any ideas what's going on?
[This functionality will benefit Cocoon's CLI, and thus Forrest. Could give a significant performance enhancement to Forrest if we can get decent caching working.]
Regards, Upayavira
# Cache configuration defaults.
# Copyright 1999-2004 The Apache Software Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. jcs.default=DC jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes jcs.default.cacheattributes.MaxObjects=100 jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache # SYSTEM GROUP ID CACHE jcs.system.groupIdCache=DC jcs.system.groupIdCache.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes jcs.system.groupIdCache.cacheattributes.MaxObjects=1000 jcs.system.groupIdCache.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache ##### AUXILIARY CACHES # Indexed Disk Cache jcs.auxiliary.DC=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory jcs.auxiliary.DC.attributes=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes #jcs.auxiliary.DC.attributes.DiskPath= # PRE-DEFINED CACHE REGIONS jcs.region.main=DC jcs.region.main.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes jcs.region.main.cacheattributes.MaxObjects=100 jcs.region.main.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache jcs.region.main.cacheattributes.UseMemoryShrinker=true jcs.region.main.cacheattributes.MaxMemoryIdleTimeSeconds=3600 jcs.region.main.cacheattributes.ShrinkerIntervalSeconds=60
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import org.apache.jcs.access.GroupCacheAccess;
import org.apache.jcs.access.exception.CacheException;
import org.apache.jcs.engine.control.CompositeCache;
import org.apache.jcs.engine.control.CompositeCacheManager;
import junit.framework.TestCase;
public class SimpleJCSTest extends TestCase {
private CompositeCacheManager cacheManager;
private JCSCacheAccess jcs;
private static final String DEFAULT_PROPERTIES = "default.ccf";
private static final int MAX_TEST_OBJECTS = 200;
private static final int MAX_CACHE_OBJECTS = 100;
private static final String REGION = "main";
public SimpleJCSTest(String arg0) {
super(arg0);
}
public void init() throws Exception {
Properties properties = new Properties();
properties.load(new FileInputStream(DEFAULT_PROPERTIES));
String key = "jcs.region." + REGION + ".cacheattributes.MaxObjects";
properties.setProperty(key, String.valueOf(MAX_CACHE_OBJECTS));
final File workDir = new File("work");
workDir.mkdir();
properties.setProperty("jcs.auxiliary.DC.attributes.DiskPath",
workDir.getAbsolutePath());
this.cacheManager = CompositeCacheManager.getUnconfiguredInstance();
this.cacheManager.configure(properties);
this.jcs = new JCSCacheAccess(cacheManager.getCache(REGION));
}
public void dispose() {
this.jcs.dispose();
this.cacheManager.release();
}
public void testExistingCache() throws Exception {
init();
for (int i=0; i< MAX_TEST_OBJECTS; i++) {
String str = Integer.toString(i);
System.out.println(i);
assertTrue(this.containsKey("abc"+str));
assertEquals("def"+str, this.get("abc"+str));
}
dispose();
}
public void testJCS() throws Exception {
init();
for (int i=0; i< MAX_TEST_OBJECTS; i++) {
String str = Integer.toString(i);
this.store("abc"+str, "def"+str);
System.out.println(i);
assertEquals("def"+str, this.get("abc"+str));
}
dispose();
}
public Object get(Object key) {
return this.jcs.get(key);
}
public void store(Object key, Object value)
throws IOException {
try {
this.jcs.put(key, value);
} catch (CacheException ce) {
System.err.println("Failure storing object " + ce.getMessage());
}
}
public boolean containsKey(Object key) {
return this.jcs.get(key) != null;
}
private static class JCSCacheAccess extends GroupCacheAccess {
private JCSCacheAccess(CompositeCache cacheControl) {
super(cacheControl);
}
protected void dispose() {
super.dispose();
}
}
}
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
