Package com.opensymphony.oscache.base

Examples of com.opensymphony.oscache.base.Cache


  }

  public void testOnGetFromCacheWhenEntryIsStale() {
    setUpCacheAdministrator();

    Cache cache = cacheAdministrator.getCache();

    cache.putInCache(CACHE_KEY, "An Object",
        new EntryRefreshPolicy() {
          /** force refresh */
          public boolean needsRefresh(CacheEntry cacheEntry) {
            return true;
          }
View Full Code Here


  }

  private void setUpCacheAdministrator() {
    cacheAdministrator = new GeneralCacheAdministrator();

    Cache cache = cacheAdministrator.getCache();

    cacheEntryEventListener = new CacheEntryEventListenerImpl();
    cache.addCacheEventListener(cacheEntryEventListener,
        CacheEntryEventListener.class);

    osCacheFacade.setCacheManager(cacheAdministrator);
  }
View Full Code Here

        }

        if (group != null) // We're flushing a group
         {
            if (cacheScope >= 0) {
                Cache cache = admin.getCache((HttpServletRequest) pageContext.getRequest(), cacheScope);
                cache.flushGroup(group);
            } else {
                throw new JspTagException("A cache group was specified for flushing, but the scope wasn't supplied or was invalid");
            }
        } else if (pattern != null) // We're flushing keys which contain the pattern
         {
            if (cacheScope >= 0) {
                Cache cache = admin.getCache((HttpServletRequest) pageContext.getRequest(), cacheScope);
                cache.flushPattern(pattern);
            } else {
                throw new JspTagException("A pattern was specified for flushing, but the scope wasn't supplied or was invalid");
            }
        } else if (key == null) // we're flushing a whole scope
         {
            if (cacheScope >= 0) {
                admin.setFlushTime(cacheScope);
            } else {
                admin.flushAll();
            }
        } else // we're flushing just one key
         {
            if (cacheScope >= 0) {
                String actualKey = admin.generateEntryKey(key, (HttpServletRequest) pageContext.getRequest(), cacheScope, language);

                Cache cache = admin.getCache((HttpServletRequest) pageContext.getRequest(), cacheScope);
                cache.flushEntry(actualKey);
            } else {
                throw new JspTagException("A cache key was specified for flushing, but the scope wasn't supplied or was invalid");
            }
        }
View Full Code Here

        // checks if the response will be a fragment of a page
        boolean fragmentRequest = isFragment(httpRequest);

        // avoid useless session creation for application scope pages (CACHE-129)
        Cache cache;
        if (cacheScope == PageContext.SESSION_SCOPE) {
            cache = admin.getSessionScopeCache(httpRequest.getSession(true));
        } else {
            cache = admin.getAppScopeCache(config.getServletContext());
        }

        // generate the cache entry key
        String key = cacheKeyProvider.createCacheKey(httpRequest, admin, cache);

        try {
            ResponseContent respContent = (ResponseContent) cache.getFromCache(key, time, cron);

            if (log.isInfoEnabled()) {
                log.info("OSCache: Using cached entry for " + key);
            }

            boolean acceptsGZip = false;
            if ((!fragmentRequest) && (lastModified != LAST_MODIFIED_OFF)) {
                long clientLastModified = httpRequest.getDateHeader(HEADER_IF_MODIFIED_SINCE); // will return -1 if no header...

                // only reply with SC_NOT_MODIFIED
                // if the client has already the newest page and the response isn't a fragment in a page
                if ((clientLastModified != -1) && (clientLastModified >= respContent.getLastModified())) {
                    ((HttpServletResponse) response).setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                    return;
                }
               
                acceptsGZip = respContent.isContentGZiped() && acceptsGZipEncoding(httpRequest);
            }

            respContent.writeTo(response, fragmentRequest, acceptsGZip);
            // acceptsGZip is used for performance reasons above; use the following line for CACHE-49
            // respContent.writeTo(response, fragmentRequest, acceptsGZipEncoding(httpRequest));
        } catch (NeedsRefreshException nre) {
            boolean updateSucceeded = false;

            try {
                if (log.isInfoEnabled()) {
                    log.info("OSCache: New cache entry, cache stale or cache scope flushed for " + key);
                }

                CacheHttpServletResponseWrapper cacheResponse = new CacheHttpServletResponseWrapper((HttpServletResponse) response, fragmentRequest, time * 1000L, lastModified, expires, cacheControlMaxAge);
                chain.doFilter(request, cacheResponse);
                cacheResponse.flushBuffer();

                // Only cache if the response is cacheable
                if (isCacheableInternal(cacheResponse)) {
                    // get the cache groups of the content
                    String[] groups = cacheGroupsProvider.createCacheGroups(httpRequest, admin, cache);
                    // Store as the cache content the result of the response
                    cache.putInCache(key, cacheResponse.getContent(), groups, expiresRefreshPolicy, null);
                    updateSucceeded = true;
                    if (log.isInfoEnabled()) {
                        log.info("OSCache: New entry added to the cache with key " + key);
                    }
                }
            } finally {
                if (!updateSucceeded) {
                    cache.cancelUpdate(key);
                }
            }
        }
    }
View Full Code Here

                                                     DEFAULT_CACHESIZE );
        }

        if( cacheSize > 0 )
        {
            m_documentCache = new Cache(true,false,false,false,
                                        OSCACHE_ALGORITHM,
                                        cacheSize);
        }
        else
        {
View Full Code Here

                                                    PROP_CACHECAPACITY,
                                                    DEFAULT_CACHECAPACITY );

        log.debug("Cache capacity "+capacity+" pages.");

        m_cache = new Cache( true, false, false );

        //
        //  OSCache documentation sucks big time.  The clazz-parameter is completely
        //  undefined; I had to read the source code to figure out that you need
        //  to declare what type of a listener you are adding by sending the type
        //  of the interface.
        //
        m_cache.addCacheEventListener( m_allCollector, CacheEntryEventListener.class );

        //
        //  FIXME: There's an interesting issue here... It would probably be
        //  possible to DOS a JSPWiki instance by bombarding it with names that
        //  do not exist, as they would fill the negcache.  Will need to
        //  think about this some more...
        //
        m_negCache = new Cache( true, false, false );

        m_textCache = new Cache( true, false, false,
                                 false,
                                 OSCACHE_ALGORITHM,
                                 capacity );

        m_historyCache = new Cache( true, false, false, false,
                                    OSCACHE_ALGORITHM,
                                    capacity );

        //
        //  Find and initialize real provider.
View Full Code Here

        log.info("Initing CachingAttachmentProvider");

        //
        // Construct an unlimited cache of Collection objects
        //
        m_cache = new Cache( true, false, true );

        //
        // Construct an unlimited cache for the individual Attachment objects.
        // Attachment name is key, the Attachment object is the cached object
        //
        m_attCache = new Cache(true, false, true);
        m_attCache.addCacheEventListener(m_allCollector,CacheEntryEventListener.class);

        //
        //  Find and initialize real provider.
        //
View Full Code Here

                                                     DEFAULT_CACHESIZE );
        }

        if( cacheSize > 0 )
        {
            m_documentCache = new Cache(true,false,false,false,
                                        OSCACHE_ALGORITHM,
                                        cacheSize);
        }
        else
        {
View Full Code Here

                                                    PROP_CACHECAPACITY,
                                                    DEFAULT_CACHECAPACITY );

        log.debug("Cache capacity "+capacity+" pages.");

        m_cache = new Cache( true, false, false );

        //
        //  OSCache documentation sucks big time.  The clazz-parameter is completely
        //  undefined; I had to read the source code to figure out that you need
        //  to declare what type of a listener you are adding by sending the type
        //  of the interface.
        //
        m_cache.addCacheEventListener( m_allCollector, CacheEntryEventListener.class );

        //
        //  FIXME: There's an interesting issue here... It would probably be
        //  possible to DOS a JSPWiki instance by bombarding it with names that
        //  do not exist, as they would fill the negcache.  Will need to
        //  think about this some more...
        //
        m_negCache = new Cache( true, false, false );

        m_textCache = new Cache( true, false, false,
                                 false,
                                 OSCACHE_ALGORITHM,
                                 capacity );

        m_historyCache = new Cache( true, false, false, false,
                                    OSCACHE_ALGORITHM,
                                    capacity );

        //
        //  Find and initialize real provider.
View Full Code Here

        log.info("Initing CachingAttachmentProvider");

        //
        // Construct an unlimited cache of Collection objects
        //
        m_cache = new Cache( true, false, true );

        //
        // Construct an unlimited cache for the individual Attachment objects.
        // Attachment name is key, the Attachment object is the cached object
        //
        m_attCache = new Cache(true, false, true);
        m_attCache.addCacheEventListener(m_allCollector,CacheEntryEventListener.class);

        //
        //  Find and initialize real provider.
        //
View Full Code Here

TOP

Related Classes of com.opensymphony.oscache.base.Cache

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.