/** * Sets the cache key for this response, which is calculated * from the provided parameters.<p> * * @param resourcename the target resource for which to create the cache key * @param cacheDirectives the cache directives of the resource (value of the property "cache") * @param online indicates if this resource is online or offline * * @return the generated cache key * * @throws CmsFlexCacheException in case the value String had a parse error */ CmsFlexCacheKey setCmsCacheKey(String resourcename, String cacheDirectives, boolean online) throws CmsFlexCacheException { m_key = new CmsFlexCacheKey(resourcename, cacheDirectives, online); if (m_key.hadParseError()) { // We throw the exception here to make sure this response has a valid key (cache=never) throw new CmsFlexCacheException(Messages.get().container( Messages.LOG_FLEXRESPONSE_PARSE_ERROR_IN_CACHE_KEY_2, cacheDirectives, resourcename)); } return m_key; }
appendKeyValue(str, CACHE_02_URI, m_uri); appendKeyValue(str, CACHE_17_SITE, m_site); appendKeyValue(str, CACHE_14_ELEMENT, m_element); appendKeyValue(str, CACHE_15_LOCALE, m_locale); appendKeyValue(str, CACHE_16_ENCODING, m_encoding); appendKeyValue(str, CACHE_13_IP, m_ip); appendKeyValue(str, CACHE_03_USER, m_user);
/** * This constructor is used when building a cache key from set of cache directives.<p> * * These directives are attached to the properties of the requested resource * on a property called "cache". * The value of this poperty that is passed in this constructor as "cacheDirectives" * is parsed to build the keys data structure.<p> * * In case a parsing error occures, the value of this key is set to "cache=never", * and the hadParseError() flag is set to true. * This is done to ensure that a valid key is always constructed with the constructor.<p> * * @param resourcename the full name of the resource including site root * @param cacheDirectives the cache directives of the resource (value of the property "cache") * @param online must be true for an online resource, false for offline resources */ public CmsFlexCacheKey(String resourcename, String cacheDirectives, boolean online) { m_resource = getKeyName(resourcename, online); m_variation = "never"; m_always = -1; m_timeout = -1; if (cacheDirectives != null) { parseFlexKey(cacheDirectives); } if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXCACHEKEY_GENERATED_1, toString())); } }
/** * Removes an entry from the cache.<p> * * @param key the key which describes the entry to remove from the cache */ void remove(CmsFlexCacheKey key) { if (!isEnabled()) { return; } CmsFlexCacheVariation o = m_keyCache.get(key.getResource()); if (o != null) { I_CmsLruCacheObject old = o.m_map.get(key.getVariation()); if (old != null) { getEntryLruCache().remove(old); } } }
Object o = m_keyCache.get(key.getResource()); if (key.getTimeout() > 0) { theCacheEntry.setDateExpiresToNextTimeout(key.getTimeout()); if (!m.containsKey(key.getVariation())) { wasAdded = m_variationCache.add(theCacheEntry); } else { theCacheEntry.setVariationData(key.getVariation(), m); m.put(key.getVariation(), theCacheEntry); theCacheEntry.setVariationData(key.getVariation(), list.m_map); list.m_map.put(key.getVariation(), theCacheEntry); m_keyCache.put(key.getResource(), list); Messages.LOG_FLEXCACHE_ADDED_ENTRY_FOR_RESOURCE_WITH_VARIATION_3, new Integer(m_size), key.getResource(), key.getVariation())); LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXCACHE_ADDED_ENTRY_1, theCacheEntry.toString()));
LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXCACHE_ADD_ENTRY_1, key.getResource())); key.setVariation(variation); if (LOG.isDebugEnabled()) { LOG.debug( Messages.get().getBundle().key( Messages.LOG_FLEXCACHE_ADD_ENTRY_WITH_VARIATION_2, key.getResource(), key.getVariation()));
CmsFlexCacheKey res_key = cache.getKey(CmsFlexCacheKey.getKeyName(m_vfsTarget, w_req.isOnline())); if (res_key != null) { variation = w_res.getCmsCacheKey().matchRequestKey(w_req.getCmsCacheKey()); if ((entry != null) && (variation != null) && w_req.isCacheable()) { if (w_res.getCmsCacheKey().getTimeout() > 0) { entry.setDateLastModifiedToPreviousTimeout(w_res.getCmsCacheKey().getTimeout()); entry.setDateExpiresToNextTimeout(w_res.getCmsCacheKey().getTimeout()); controller.updateDates(entry.getDateLastModified(), entry.getDateExpires()); } else {
/** * Adds a key with a new, empty variation map to the cache.<p> * * @param key the key to add to the cache. */ void putKey(CmsFlexCacheKey key) { if (!isEnabled()) { return; } Object o = m_keyCache.get(key.getResource()); if (o == null) { // No variation map for this resource yet, so create one CmsFlexCacheVariation variationMap = new CmsFlexCacheVariation(key); m_keyCache.put(key.getResource(), variationMap); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXCACHE_ADD_KEY_1, key.getResource())); } } // If != null the key is already in the cache, so we just do nothing }
/** * This constructor is used when building a cache key from a request.<p> * * The request contains several data items that are neccessary to construct * the output. These items are e.g. the Query-String, the requested resource, * the current time etc. etc. * All required items are saved in the constructed cache - key.<p> * * @param req the request to construct the key for * @param target the requested resource in the OpenCms VFS * @param online must be true for an online resource, false for offline resources */ public CmsFlexRequestKey(HttpServletRequest req, String target, boolean online) { // store the request m_request = req; // fetch the cms from the request CmsObject cms = CmsFlexController.getCmsObject(req); // store the request context m_context = cms.getRequestContext(); // calculate the resource name m_resource = CmsFlexCacheKey.getKeyName(m_context.addSiteRoot(target), online); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXREQUESTKEY_CREATED_NEW_KEY_1, m_resource)); } }
String variation = v.m_key.matchRequestKey(key);
case 4: // params if (v != null) { m_params = parseValueList(v); } else { m_params = Collections.emptySet(); m_noparams = parseValueList(v); } else { break; case 7: // session m_session = parseValueList(v); if (m_session.size() <= 0) { m_schemes = parseValueList(v); break; case 9: // ports Set<String> ports = parseValueList(v); m_ports = new HashSet<Integer>(ports.size()); for (String p : ports) { case 18: // attrs if (v != null) { m_attrs = parseValueList(v); } else { m_attrs = null; m_noattrs = parseValueList(v); } else {
CmsFlexCacheVariation o = m_keyCache.get(key.getResource()); if (key.getTimeout() > 0) { theCacheEntry.setDateExpiresToNextTimeout(key.getTimeout()); if (!m.containsKey(key.getVariation())) { wasAdded = m_variationCache.add(theCacheEntry); } else { theCacheEntry.setVariationData(key.getVariation(), m); m.put(key.getVariation(), theCacheEntry); theCacheEntry.setVariationData(key.getVariation(), list.m_map); list.m_map.put(key.getVariation(), theCacheEntry); m_keyCache.put(key.getResource(), list); Messages.LOG_FLEXCACHE_ADDED_ENTRY_FOR_RESOURCE_WITH_VARIATION_3, new Integer(m_size), key.getResource(), key.getVariation())); LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXCACHE_ADDED_ENTRY_1, theCacheEntry.toString()));
LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXCACHE_ADD_ENTRY_1, key.getResource())); key.setVariation(variation); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key( Messages.LOG_FLEXCACHE_ADD_ENTRY_WITH_VARIATION_2, key.getResource(), key.getVariation()));
CmsFlexCacheKey res_key = cache.getKey(CmsFlexCacheKey.getKeyName(m_vfsTarget, w_req.isOnline())); if (res_key != null) { variation = w_res.getCmsCacheKey().matchRequestKey(w_req.getCmsCacheKey()); if ((entry != null) && (variation != null) && w_req.isCacheable()) { if (w_res.getCmsCacheKey().getTimeout() > 0) { entry.setDateLastModifiedToPreviousTimeout(w_res.getCmsCacheKey().getTimeout()); entry.setDateExpiresToNextTimeout(w_res.getCmsCacheKey().getTimeout()); controller.updateDates(entry.getDateLastModified(), entry.getDateExpires()); } else {
/** * Removes an entry from the cache.<p> * * @param key the key which describes the entry to remove from the cache */ void remove(CmsFlexCacheKey key) { if (!isEnabled()) { return; } Object o = m_keyCache.get(key.getResource()); if (o != null) { //Object old = ((HashMap)o).remove(key.Variation); Object old = ((HashMap)o).get(key.getVariation()); if (old != null) { getEntryLruCache().remove((I_CmsLruCacheObject)old); } } }
/** * Adds a key with a new, empty variation map to the cache.<p> * * @param key the key to add to the cache. */ void putKey(CmsFlexCacheKey key) { if (!isEnabled()) { return; } Object o = m_keyCache.get(key.getResource()); if (o == null) { // No variation map for this resource yet, so create one CmsFlexCacheVariation variationMap = new CmsFlexCacheVariation(key); m_keyCache.put(key.getResource(), variationMap); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXCACHE_ADD_KEY_1, key.getResource())); } } // If != null the key is already in the cache, so we just do nothing }
m_resource = CmsFlexCacheKey.getKeyName(m_context.addSiteRoot(target), online);
String variation = v.m_key.matchRequestKey(key);
case 4: // params if (v != null) { m_params = parseValueList(v); } else { m_params = Collections.EMPTY_SET; if (v != null) { m_noparams = parseValueList(v); } else { break; case 7: // session m_session = parseValueList(v); if (m_session.size() <= 0) { m_schemes = parseValueList(v); break; case 9: // ports m_ports = parseValueList(v); break; case 11: // previous parse error - ignore
/** * This constructor is used when building a cache key from set of cache directives.<p> * * These directives are attached to the properties of the requested resource * on a property called "cache". * The value of this poperty that is passed in this constructor as "cacheDirectives" * is parsed to build the keys data structure.<p> * * In case a parsing error occures, the value of this key is set to "cache=never", * and the hadParseError() flag is set to true. * This is done to ensure that a valid key is always constructed with the constructor.<p> * * @param resourcename the full name of the resource including site root * @param cacheDirectives the cache directives of the resource (value of the property "cache") * @param online must be true for an online resource, false for offline resources */ public CmsFlexCacheKey(String resourcename, String cacheDirectives, boolean online) { m_resource = getKeyName(resourcename, online); m_variation = "never"; m_always = -1; m_timeout = -1; if (cacheDirectives != null) { parseFlexKey(cacheDirectives); } if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXCACHEKEY_GENERATED_1, toString())); } }