TOC PREV NEXT INDEX




Using the Cache Manager


To enable caching in your application, you must create and configure the CacheManager. Normally, you would configure the CacheManager with one or both of the provided MemoryCache and/or FileCache. In addition, you can implement the ice.net.Cache interface and write your own cache with custom cache behaviors, etc. as required.

To configure a CacheManager, use code similar to the following in your application:

    import ice.net.Cache;

    import ice.net.CacheManager;

    import ice.net.FileCache;

    import ice.net.HttpURLConnection;

    import ice.net.MemoryCache;

    import ice.util.ICEException;

    

    CacheManager cacheManager = new CacheManager();
 

Once you have created a CacheManager you need to register one or more cache implementations with it.

To configure a MemoryCache, use code similar to this:

    Cache memoryCache = new MemoryCache();

    memoryCache.setMaxSize(1048576); // 1 MB

    cacheManager.addCache(memoryCache);
 

To configure a FileCache, use code similar to this:

    try {

        Cache fileCache = new FileCache("c:/ib_cache");

        fileCache.setMaxSize(10485760); // 10 MB

        cacheManager.addCache(fileCache);

    } catch (ICEException exception) {

        // handle the exception.



    }
 

Finally, enable caching and set the GlobalCacheManager:

    cacheManager.useCache(true);

    HttpURLConnection.setGlobalCacheManager(cacheManager);
 

For more information on the cache manager, see the API documentation for ice.net.CacheManager.

Note: Under almost all circumstances, an application with a properly configured CacheManager will provide dramatic performance improvements over an equivalent application configured without caching.


Copyright 2005. ICEsoft Technologies, Inc.
http://www.icesoft.com

TOC PREV NEXT INDEX