[Opensymphony-oscache] Configuration and Classloading questions

garu <[email protected]> Mon, 25 Jul 2005 01:26:31 CDT
Newsgroups gmane.comp.java.open-symphony.os-cache
Message-ID <4266401.1122272986026.JavaMail.os-j2ee@opensymphony01.contegix.com>
If this may help, here's what i do (more or less, i stripped away some parts specific to my application), to use an oscache.properties out of the classpath, so that i can make dynamic both the properties file and the caching path.

    public void initCacheAdministrator(ServletContext sctx) {
        Properties oscacheProps = new Properties();
        try {
            String cachePathPropertyName = "cache.path";
            String oscacheConfigFileName = "oscache.properties";
            String oscacheConfig = (String) sctx.getAttribute("configInfoPath");
            File cfgPath = new File(oscacheConfig);
            File cfgFile = new File(cfgPath, getContextPath(sctx)
                    + oscacheConfigFileName);
            logger.info("Loading cache configuration from: " + cfgFile.getPath());
            InputStream input = new java.io.FileInputStream(cfgFile);
            oscacheProps.load(input);
            // the cache.path property only contains the ending part of the path
            String cachePath = oscacheProps.getProperty(cachePathPropertyName);
            cachePath = System.getProperty("auto.application.data.dir") 
                    + "/" + getContextPath(sctx) + cachePath;
            oscacheProps.setProperty(cachePathPropertyName, cachePath);
            logger.info("Cache path set to: " + cachePath);

            ServletCacheAdministrator.getInstance(sctx, oscacheProps);
        } catch (Exception e) {
            logger.error(e);
        }

---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=4554&messageID=11299#11299