/** * 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); }
String oName = f.getAbsolutePath().substring(CmsImageLoader.getImageRepositoryPath().length()); oName = CmsStringUtil.substitute(oName, "\\", "/"); if (!oName.startsWith("/")) {
/** * Reads all cached images.<p> * * @param cms the cms context * @param withVariations if also variations should be read * @param showSize if it is needed to compute the image size * @param statsOnly if only statistical information should be retrieved */ private void init(CmsObject cms, boolean withVariations, boolean showSize, boolean statsOnly) { File basedir = new File(CmsImageLoader.getImageRepositoryPath()); try { CmsObject clonedCms = OpenCms.initCmsObject(cms); // only online images get caches clonedCms.getRequestContext().setCurrentProject(clonedCms.readProject(CmsProject.ONLINE_PROJECT_ID)); // paths are always root path clonedCms.getRequestContext().setSiteRoot(""); // get the images visitImages(clonedCms, basedir, withVariations, showSize, statsOnly); } catch (CmsException e) { // should never happen } m_variations = Collections.unmodifiableMap(m_variations); m_sizes = Collections.unmodifiableMap(m_sizes); m_lengths = Collections.unmodifiableMap(m_lengths); }
/** * @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)); } }
/** * @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)); } }