Package ch.entwine.weblounge.common.request

Examples of ch.entwine.weblounge.common.request.CacheHandle


   *      ch.entwine.weblounge.common.request.WebloungeResponse, long, long)
   */
  public CacheHandle startResponse(CacheTag[] uniqueTags,
      WebloungeRequest request, WebloungeResponse response,
      long expirationTime, long revalidationTime) {
    CacheHandle hdl = new TaggedCacheHandle(uniqueTags, expirationTime, revalidationTime);
    return startResponse(hdl, request, response);
  }
View Full Code Here


    try {

      // Is the response ready to be cached?
      if (tx.isValid() && response.isValid() && response.getStatus() == HttpServletResponse.SC_OK) {
        logger.trace("Writing response for {} to the cache", response);
        CacheHandle cacheHdl = tx.getHandle();
        String encoding = cacheableResponse.getCharacterEncoding();
        CacheEntry entry = new CacheEntry(cacheHdl, tx.getContent(), encoding, tx.getHeaders());
        Element element = new Element(new CacheEntryKey(cacheHdl), entry);
        element.setTimeToLive((int) (cacheHdl.getCacheExpirationTime() / 1000));
        cache.put(element);

        // Write cache and content relevant headers
        writeCacheHeaders(response, entry, true);
        writeContentHeaders(response, entry);
View Full Code Here

   * {@link ch.entwine.weblounge.cache.impl.CacheableHttpServletResponse#startTransaction(ch.entwine.weblounge.common.request.CacheHandle, java.lang.String, ch.entwine.weblounge.cache.StreamFilter)}
   * .
   */
  @Test
  public void testStartTransaction() {
    CacheHandle hdl = new CacheHandleImpl("/a/b/c", expirationTime, recheckTime);
    CacheTransaction tx = response.startTransaction(hdl, null);
    assertNotNull(tx);
    assertEquals(hdl, tx.getHandle());
  }
View Full Code Here

  @Test
  public void testGetETag() throws Exception {
    String eTag = entry.getETag();
    assertNotNull(eTag);
    Thread.sleep(1000);
    CacheHandle newHandle = new TaggedCacheHandle(tags.getTags(), expirationTime, recheckTime);
    String newETag = new CacheEntry(newHandle, content.getBytes(), encoding, headers).getETag();
    assertFalse(eTag.equals(newETag));
  }
View Full Code Here

      return false;
    if (cacheHandle != null)
      throw new IllegalStateException("The response is already being cached");

    // Is the response in the cache?
    CacheHandle hdl = cache.startResponse(tags, request.get(), this, expirationTime, revalidationTime);
    if (hdl == null)
      return true;

    // It's not, meaning we need to do the processing ourselves
    cacheHandle = new WeakReference<CacheHandle>(hdl);
View Full Code Here

    if (modificationDate == null)
      return this.modificationDate;
    this.modificationDate = modificationDate.after(this.modificationDate) ? modificationDate : this.modificationDate;
    if (cacheHandle == null)
      return this.modificationDate;
    CacheHandle hdl = cacheHandle.get();
    if (hdl == null)
      return this.modificationDate;
    return hdl.setModificationDate(modificationDate);
  }
View Full Code Here

   */
  @Override
  public Date getModificationDate() {
    if (cacheHandle == null)
      return modificationDate.getTime() > 0 ? modificationDate : new Date();
    CacheHandle hdl = cacheHandle.get();
    if (hdl == null)
      return modificationDate.getTime() > 0 ? modificationDate : new Date();
    return hdl.getModificationDate();
  }
View Full Code Here

   * @see ch.entwine.weblounge.common.request.WebloungeResponse#setClientRevalidationTime(long)
   */
  public void setClientRevalidationTime(long revalidationTime) {
    if (cacheHandle == null)
      return;
    CacheHandle hdl = cacheHandle.get();
    if (hdl == null)
      return;
    hdl.setClientRevalidationTime(Math.min(revalidationTime, hdl.getClientRevalidationTime()));
  }
View Full Code Here

   * @see ch.entwine.weblounge.common.request.WebloungeResponse#getClientRevalidationTime()
   */
  public long getClientRevalidationTime() {
    if (cacheHandle == null)
      return 0;
    CacheHandle hdl = cacheHandle.get();
    if (hdl == null)
      return 0;
    return hdl.getClientRevalidationTime();
  }
View Full Code Here

   * @see ch.entwine.weblounge.common.request.WebloungeResponse#setCacheExpirationTime(long)
   */
  public void setCacheExpirationTime(long expirationTime) {
    if (cacheHandle == null)
      return;
    CacheHandle hdl = cacheHandle.get();
    if (hdl == null)
      return;
    hdl.setCacheExpirationTime(Math.min(expirationTime, hdl.getCacheExpirationTime()));

    // The recheck time can't be longer than the valid time
    setClientRevalidationTime(expirationTime);
  }
View Full Code Here

TOP

Related Classes of ch.entwine.weblounge.common.request.CacheHandle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.