• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

JCS shared cache not working

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have two projects running. My goal is to create a cache in the first application and then access this cache from the second project.
The code is as follows:

Project1:
public class ErrorLogCacheManagerMain {

public static JCS cache;
public static void main(String[] args) throws Exception {
cache = JCS.getInstance( "errorLogCache" );
String url = "jdbc:oracle:thin:@localhost:1521:sysdba";
Properties props = new Properties();
props.setProperty("user", "dev");
props.setProperty("password", "dev123");
Connection conn = DriverManager.getConnection(url,props);
String sql ="SELECT * from DEV.ERROR_LOG";
String groupName = "group1";
ArrayList<ErrorLogEntity> errorLogEntityList = new ArrayList<ErrorLogEntity>();
PreparedStatement preStatement = conn.prepareStatement(sql);

ResultSet result = preStatement.executeQuery();

while(result.next()){
ErrorLogEntity errorLogEntity = new ErrorLogEntity();
errorLogEntity.setAddDate(result.getDate("ADD_DATE"));
errorLogEntity.setErId(result.getInt("ER_ID"));
errorLogEntity.setErrorDesc(result.getString("ER_DESC"));
errorLogEntity.setErrorStatus(result.getInt("ER_STATUS"));
errorLogEntity.setFlag(result.getString("SENT_FLAG"));
errorLogEntity.setRefId(result.getString("REF_ID"));
cache.putInGroup(errorLogEntity.getErId(), groupName, errorLogEntity);
errorLogEntity = null;
}
Set keys = cache.getGroupKeys(groupName);
for(Object key : keys) {
System.out.println(key);
ErrorLogEntity errorLogEntity = (ErrorLogEntity) cache.getFromGroup(key, groupName);
System.out.println(errorLogEntity);
System.out.println(errorLogEntity.getErId());
System.out.println(errorLogEntity.getRefId());
System.out.println(errorLogEntity.getAddDate());
System.out.println(errorLogEntity.getErrorDesc());
System.out.println(errorLogEntity.getErrorStatus());
System.out.println(errorLogEntity.getFlag());
}
}
}
cache.ccf 1:
# DEFAULT CACHE REGION
jcs.default=DC
jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=1000
jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.default.cacheattributes.UseMemoryShrinker=true
jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
jcs.default.cacheattributes.DiskUsagePatternName=UPDATE
jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.default.elementattributes.IsEternal=false
jcs.default.elementattributes.MaxLifeSeconds=21600
jcs.default.elementattributes.IdleTime=1800
jcs.default.elementattributes.IsSpool=true
jcs.default.elementattributes.IsRemote=true
jcs.default.elementattributes.IsLateral=true

# PREDEFINED CACHE REGIONS
jcs.region.errorLogCache=DC
jcs.region.errorLogCache.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.region.errorLogCache.cacheattributes.MaxObjects=1000
jcs.region.errorLogCache.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.region.errorLogCache.cacheattributes.UseMemoryShrinker=true
jcs.region.errorLogCache.cacheattributes.MaxMemoryIdleTimeSeconds=20
jcs.region.errorLogCache.cacheattributes.ShrinkerIntervalSeconds=10
jcs.region.errorLogCache.cacheattributes.MaxSpoolPerRun=500
jcs.region.errorLogCache.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.region.errorLogCache.elementattributes.IsEternal=false

# AVAILABLE AUXILIARY CACHES
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=C:/Users/Debanjan/Desktop/Exp
jcs.auxiliary.DC.attributes.MaxPurgatorySize=10000000
jcs.auxiliary.DC.attributes.MaxKeySize=1000000
jcs.auxiliary.DC.attributes.MaxRecycleBinSize=5000
jcs.auxiliary.DC.attributes.OptimizeAtRemoveCount=300000
jcs.auxiliary.DC.attributes.ShutdownSpoolTimeLimit=60


Project 2:
public class CacheMainTest {

public static JCS cache;
public static String groupName = "group1";
public static void main(String[] args) throws InterruptedException, CacheException {
cache = JCS.getInstance( "errorLogCache" );
System.out.println(cache);
Set keys = cache.getGroupKeys(groupName);
System.out.println(keys);
for(Object key : keys) {
System.out.println(key);
ErrorLogEntity errorLogEntity = (ErrorLogEntity) cache.getFromGroup(key, groupName);
System.out.println(errorLogEntity);
System.out.println(errorLogEntity.getErId());
System.out.println(errorLogEntity.getRefId());
System.out.println(errorLogEntity.getAddDate());
System.out.println(errorLogEntity.getErrorDesc());
System.out.println(errorLogEntity.getErrorStatus());
System.out.println(errorLogEntity.getFlag());
}

}
}

cache.ccf 2 :
same as cache.ccf 1

It works fine when I access the cache from within project 1. But when I try to do the same from project 2, I get the follwoing:
[ main] CompositeCacheManager INFO Creating cache manager from config file: /cache.ccf
[ main] ThreadPoolManager INFO thread_pool.default PoolConfiguration = useBoundary = [true] boundarySize = [2000] maximumPoolSize = [150] minimumPoolSize = [4] keepAliveTime = [300000] whenBlockedPolicy = [RUN] startUpSize = [4]
[ main] CompositeCacheConfigurator INFO Setting default auxiliaries to DC
[ main] CompositeCacheConfigurator INFO setting defaultCompositeCacheAttributes to [ useLateral = true, useRemote = true, useDisk = true, maxObjs = 1000, maxSpoolPerRun = -1, diskUsagePattern = 1 ]
[ main] CompositeCacheConfigurator INFO setting defaultElementAttributes to [ IS_LATERAL = true, IS_SPOOL = true, IS_REMOTE = true, IS_ETERNAL = false, MaxLifeSeconds = 21600, IdleTime = 1800, CreateTime = 1444248197766, LastAccessTime = 1444248197766, getTimeToLiveSeconds() = 21600, createTime = 1444248197766 ]
[ main] LRUMemoryCache INFO initialized LRUMemoryCache for errorLogCache
[ main] CompositeCache INFO Constructed cache with name [errorLogCache] and cache attributes [ useLateral = true, useRemote = true, useDisk = true, maxObjs = 1000, maxSpoolPerRun = 500, diskUsagePattern = 0 ]
[ main] IndexedDiskCache INFO Region [errorLogCache] Cache file root directory: C:/Users/Debanjan/Desktop/Exp
[ main] IndexedDiskCache INFO Region [errorLogCache] Set maxKeySize to: '1000000'
[ main] IndexedDiskCache INFO Region [errorLogCache] Indexed Disk Cache is alive.
[ main] CompositeCacheConfigurator INFO Parsed regions [errorLogCache]
[ main] CompositeCacheConfigurator INFO Finished configuration in 235 ms.
org.apache.jcs.JCS@71dac704
[]
[ Thread-1] IndexedDiskCache WARN Region [errorLogCache] Disk cache not shutdown properly, shutting down now.
[ndexedDiskCache-DisposalThread] IndexedDisk WARN Failed to delete errorLogCache.key 0
[ndexedDiskCache-DisposalThread] IndexedDisk WARN Failed to delete errorLogCache.key 1
[ndexedDiskCache-DisposalThread] IndexedDisk WARN Failed to delete errorLogCache.key 2
[ndexedDiskCache-DisposalThread] IndexedDisk WARN Failed to delete errorLogCache.key 3
[ndexedDiskCache-DisposalThread] IndexedDisk WARN Failed to delete errorLogCache.key 4
[ndexedDiskCache-DisposalThread] IndexedDisk WARN Failed to delete errorLogCache.key 5
[ndexedDiskCache-DisposalThread] IndexedDisk WARN Failed to delete errorLogCache.key 6
[ndexedDiskCache-DisposalThread] IndexedDisk WARN Failed to delete errorLogCache.key 7
[ndexedDiskCache-DisposalThread] IndexedDisk WARN Failed to delete errorLogCache.key 8
[ndexedDiskCache-DisposalThread] IndexedDisk WARN Failed to delete errorLogCache.key 9
[ndexedDiskCache-DisposalThread] IndexedDisk ERROR java.lang.IllegalStateException: Failed to delete errorLogCache.key
[ndexedDiskCache-DisposalThread] IndexedDiskCache ERROR Region [errorLogCache] Problem storing keys.
java.lang.IllegalStateException: Failed to delete errorLogCache.key
at org.apache.jcs.auxiliary.disk.indexed.IndexedDisk.reset(IndexedDisk.java:269)
at org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCache.saveKeys(IndexedDiskCache.java:383)
at org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCache.disposeInternal(IndexedDiskCache.java:976)
at org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCache.access$000(IndexedDiskCache.java:60)
at org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCache$1.run(IndexedDiskCache.java:924)
at java.lang.Thread.run(Thread.java:745)
[ndexedDiskCache-DisposalThread] IndexedDiskCache INFO Region [errorLogCache] Shutdown complete.
 
Just the other day, I was thinking ... about this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic