/** * Removes all expired image cache entries from the RFS cache.<p> * * Empty directories are removed as well.<p> * * @param maxAge the maximum age of the image cache files in hours (or fractions of hours) * * @return the total number of deleted resources */ public static int cleanImageCache(float maxAge) { // calculate oldest possible date for the cache files long expireDate = System.currentTimeMillis() - (long)(maxAge * 60f * 60f * 1000f); File basedir = new File(CmsImageLoader.getImageRepositoryPath()); // perform the cache cleanup return cleanImageCache(expireDate, basedir); }
/** * Removes all expired image cache entries from the RFS cache.<p> * * Empty directories are removed as well.<p> * * @param maxAge the maximum age of the image cache files in hours (or fractions of hours) * * @return the total number of deleted resources */ public static int cleanImageCache(float maxAge) { // calculate oldest possible date for the cache files long expireDate = System.currentTimeMillis() - (long)(maxAge * 60f * 60f * 1000f); File basedir = new File(CmsImageLoader.getImageRepositoryPath()); // perform the cache cleanup return cleanImageCache(expireDate, basedir); }
/** * @see org.opencms.main.I_CmsEventListener#cmsEvent(org.opencms.main.CmsEvent) */ public void cmsEvent(CmsEvent event) { if (event == null) { return; } // only react on the clear caches event int type = event.getType(); if (type != I_CmsEventListener.EVENT_CLEAR_CACHES) { return; } // only react if the clear images cache parameter is set Map data = event.getData(); if (data == null) { return; } Object param = data.get(PARAM_CLEAR_IMAGES_CACHE); if (param == null) { return; } float age = -1; if (param instanceof String) { age = Float.valueOf((String)param).floatValue(); } else if (param instanceof Number) { age = ((Number)param).floatValue(); } CmsImageCacheCleanupJob.cleanImageCache(age); }
/** * @see org.opencms.main.I_CmsEventListener#cmsEvent(org.opencms.main.CmsEvent) */ public void cmsEvent(CmsEvent event) { if (event == null) { return; } // only react on the clear caches event int type = event.getType(); if (type != I_CmsEventListener.EVENT_CLEAR_CACHES) { return; } // only react if the clear images cache parameter is set Map<String, ?> data = event.getData(); if (data == null) { return; } Object param = data.get(PARAM_CLEAR_IMAGES_CACHE); if (param == null) { return; } float age = -1; if (param instanceof String) { age = Float.valueOf((String)param).floatValue(); } else if (param instanceof Number) { age = ((Number)param).floatValue(); } CmsImageCacheCleanupJob.cleanImageCache(age); }
File f = files[i]; if (f.isDirectory()) { count += cleanImageCache(maxAge, f);
File f = files[i]; if (f.isDirectory()) { count += cleanImageCache(maxAge, f);
/** * @see org.opencms.scheduler.I_CmsScheduledJob#launch(CmsObject, Map) */ public String launch(CmsObject cms, Map<String, String> parameters) throws Exception { if (!CmsImageLoader.isEnabled() || (CmsImageLoader.getImageRepositoryPath() == null)) { // scaling functions are not available return Messages.get().getBundle().key(Messages.LOG_IMAGE_SCALING_DISABLED_0); } String maxAgeStr = parameters.get(PARAM_MAXAGE); float maxAge; try { maxAge = Float.parseFloat(maxAgeStr); } catch (NumberFormatException e) { // in case of an error, use maxage of one week maxAge = 24f * 7f; LOG.error( Messages.get().getBundle().key(Messages.LOG_IMAGE_CACHE_BAD_MAXAGE_2, maxAgeStr, new Float(maxAge))); } // now perform the image cache cleanup int count = cleanImageCache(maxAge); return Messages.get().getBundle().key(Messages.LOG_IMAGE_CACHE_CLEANUP_COUNT_1, new Integer(count)); } }
/** * @see org.opencms.scheduler.I_CmsScheduledJob#launch(CmsObject, Map) */ public String launch(CmsObject cms, Map parameters) throws Exception { if (!CmsImageLoader.isEnabled() || (CmsImageLoader.getImageRepositoryPath() == null)) { // scaling functions are not available return Messages.get().getBundle().key(Messages.LOG_IMAGE_SCALING_DISABLED_0); } String maxAgeStr = (String)parameters.get(PARAM_MAXAGE); float maxAge; try { maxAge = Float.parseFloat(maxAgeStr); } catch (NumberFormatException e) { // in case of an error, use maxage of one week maxAge = 24f * 7f; LOG.error(Messages.get().getBundle().key( Messages.LOG_IMAGE_CACHE_BAD_MAXAGE_2, maxAgeStr, new Float(maxAge))); } // now perform the image cache cleanup int count = cleanImageCache(maxAge); return Messages.get().getBundle().key(Messages.LOG_IMAGE_CACHE_CLEANUP_COUNT_1, new Integer(count)); } }