public void setMaxSize(int maxsize) { _maxsize = maxsize; for (int j = 0; j < _caches.length; ++j) if (_caches[j] != null) synchronized (_caches[j]) { _caches[j].setMaxSize(maxsize); } }
/** Constructs a cache map with the specified max size and lifetime. * @param accessOrder whether to use the access order. * Specify false for the insertion order. * @since 6.0.0 */ public CacheMap(int maxSize, int lifetime, boolean accessOrder) { this(accessOrder); setMaxSize(maxSize); setLifetime(lifetime); } /** Constructs a cache map.
public String getDownloadMediaURI(Media media, String pathInfo) { if (media == null) throw new IllegalArgumentException("null media"); if (_meds == null) { _meds = new CacheMap<String, Media>(); _meds.setMaxSize(500); _meds.setLifetime(15 * 60 * 1000); //15 minutes (CONSIDER: configurable) } else { housekeep(); } String medId = Strings.encode(new StringBuffer(12).append(DOWNLOAD_PREFIX), _medId++).toString(); _meds.put(medId, media); final StringBuffer sb = new StringBuffer(64).append("/view/").append(getId()).append('/').append(medId) .append('/'); Strings.encode(sb, System.identityHashCode(media) & 0xffff); if (pathInfo != null && pathInfo.length() > 0) { sb.append('/').append(FILENAME_HOLDER); if (pathInfo.charAt(0) == '/') pathInfo = pathInfo.substring(1); String uri = getUpdateURI(sb.toString()); int holderPos = uri.lastIndexOf(FILENAME_HOLDER); return uri.substring(0, holderPos) + encodeFilename(pathInfo) + uri.substring(holderPos + FILENAME_HOLDER.length()); } return getUpdateURI(sb.toString()); }
private CacheMap<K, V> getCache(Object key) { int j = getInnerCacheHashCode(key); j = (j >= 0 ? j: -j) % _caches.length; CacheMap<K, V> cache = _caches[j]; if (cache == null) synchronized (this) { cache = _caches[j]; if (cache == null) { cache = new CacheMap<K, V>(4); cache.setMaxSize(_maxsize); cache.setLifetime(_lifetime); _caches[j] = cache; } } return cache; }
/** Initializes the downloader. */ public static void init(WebApp wapp) { if (DHtmlUpdateServlet.getAuProcessor(wapp, URI_PREFIX) == null) { final String clsnm = Library.getProperty("org.zkoss.zkmax.zul.FiledownloadListener.class"); if (clsnm != null) { try { _listener = (FiledownloadListener)Classes.newInstanceByThread(clsnm); } catch (Throwable ex) { log.warning("Failed to instantiate "+clsnm); } } DHtmlUpdateServlet .addAuProcessor(wapp, URI_PREFIX, new AuDownloader()); _dls.setMaxSize(Library.getIntProperty( "org.zkoss.zk.download.resumable.maxsize", 1024 * 4)); _dls.setLifetime(Library.getIntProperty( "org.zkoss.zk.download.resumable.lifetime", 4 * 60 * 60) * 1000); } }