Package org.apache.cocoon.caching

Examples of org.apache.cocoon.caching.Cache


                    SourceResolver resolver,
                    Map objectModel,
                    String src,
                    Parameters par
    ) throws Exception {
        Cache cache = (Cache)this.manager.lookup(Cache.ROLE);

        try {
            cache.clear();
            return EMPTY_MAP;
        } catch (Exception ex) {
      if (this.getLogger().isDebugEnabled()) {
                getLogger().debug("Exception while trying to Clear Cache", ex);
            }
View Full Code Here


        if ( "remove".equals(action)) {
            final String cacheRole = par.getParameter("cache-role", Cache.ROLE);
            final String cacheKey = par.getParameter("cache-key");
       
            if ( cacheKey != null ) {
                Cache cache = null;

                IdentifierCacheKey key = new IdentifierCacheKey(cacheKey, true);
                try {
                    cache = (Cache)this.manager.lookup(cacheRole);
                    cache.remove(key);
               
                    key = new IdentifierCacheKey(cacheKey, false);
                    cache.remove(key);
                } catch (Exception ex) {
                    if (this.getLogger().isDebugEnabled()) {
                        getLogger().debug("Exception while trying to remove entry "+cacheKey+" from Cache with role " + cacheRole, ex);
                    }
                } finally {
View Full Code Here

                    Map objectModel,
                    String src,
                    Parameters par
    ) throws Exception {
        final String cacheRole = par.getParameter("cache-role", Cache.ROLE + "/EventAware");
        Cache cache = (Cache)this.manager.lookup(cacheRole);
        try {
            // FIXME - This cast might not work with every container!
            if (cache instanceof EventAwareCacheImpl) {
                String eventName = par.getParameter("event");
                if (getLogger().isDebugEnabled()) {
View Full Code Here

                    Map objectModel,
                    String src,
                    Parameters par
    ) throws Exception {
        final String cacheRole = par.getParameter("cache-role", Cache.ROLE);
        Cache cache = null;

        try {
            cache = (Cache)this.manager.lookup(cacheRole);
            cache.clear();
            return EMPTY_MAP;
        } catch (Exception ex) {
          if (this.getLogger().isDebugEnabled()) {
                getLogger().debug("Exception while trying to clear Cache with role " + cacheRole, ex);
            }
View Full Code Here

            if (this.getLogger().isDebugEnabled()) {
                this.getLogger().debug("Refreshing " + this.uri);
            }
           
            Source source = null;
            Cache cache = null;
            try {
               
                cache = (Cache) this.manager.lookup(this.cacheRole);
                source = this.resolver.resolveURI(this.uri);
               
                // check if the source is really expired and invalid
                CachedSourceResponse response = (CachedSourceResponse) cache.get(this.cacheKey);
                if (response != null) {
                    final SourceValidity sourceValidity = response.getValidityObjects()[1];
                    if (CachingSource.isValid(sourceValidity, source)) {
                        if (getLogger().isDebugEnabled()) {
                            getLogger().debug("Cached response is still valid " +
                                "for source " + this.uri + ".");
                        }
                        response.getValidityObjects()[0] = new ExpiresValidity(this.expires * 1000);
                        return;
                    }
                }
               
                if (source.exists()) {
                   
                    // what is in the cached response?
                    byte[] binary = null;
                    byte[] xml = null;
                    if (response != null) {
                        binary = response.getBinaryResponse();
                        xml = response.getXMLResponse();
                    }
                   
                    // create a new cached response
                    final ExpiresValidity cacheValidity = new ExpiresValidity(this.expires * 1000);
                    final SourceValidity sourceValidity = source.getValidity();
                    response = new CachedSourceResponse(new SourceValidity[] {cacheValidity, sourceValidity});
                   
                    // only create objects that have previously been used
                    if (binary != null) {
                        binary = CachingSource.readBinaryResponse(source);
                        response.setBinaryResponse(binary);
                    }
                    if (xml != null) {
                        xml = CachingSource.readXMLResponse(source, binary, this.manager);
                        response.setXMLResponse(xml);
                    }
                    // meta info is always set
                    response.setExtra(CachingSource.readMeta(source));
                    cache.store(this.cacheKey, response);
                }
                else if (response != null) {
                    // FIXME: There is a potential problem when the parent
                    // source has not yet been updated thus listing this
                    // source still as one of its children. We'll have to remove
                    // the parent's cached response here too.
                    if (getLogger().isDebugEnabled()) {
                        getLogger().debug("Source " + this.uri + " no longer exists." +
                            " Throwing out cached response.");
                    }
                    cache.remove(this.cacheKey);
                }
            } catch (Exception e) {
                if (!failSafe) {
                    // the content expires, so remove it
                    cache.remove(cacheKey);
                    getLogger().warn("Exception during updating of source " + this.uri, e);
                }
                else {
                    getLogger().warn("Updating of source " + this.uri + " failed. " +
                        "Cached response (if any) will be stale.", e);
View Full Code Here

    }
   
    public void service(ServiceManager manager) throws ServiceException {
        m_manager = manager;
        m_resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
        Cache cache = (Cache) manager.lookup(Cache.ROLE + "/EventAware");
        if (cache instanceof EventAware) {
            m_cache = (EventAware) cache;
        } else {
            getLogger().warn("EventAware cache was not found: sources won't be cacheable.");
        }
View Full Code Here

                    SourceResolver resolver,
                    Map objectModel,
                    String src,
                    Parameters par
    ) throws Exception {
        Cache cache = (Cache)this.manager.lookup(Cache.ROLE + "/EventAware");
        if (cache instanceof EventAwareCacheImpl) {
            String eventName = par.getParameter("event");
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Configured for cache event named: " + eventName);
            }
View Full Code Here

        if ( "remove".equals(action)) {
            final String cacheRole = par.getParameter("cache-role", Cache.ROLE);
            final String cacheKey = par.getParameter("cache-key");
       
            if ( cacheKey != null ) {
                Cache cache = null;

                SimpleCacheKey key = new SimpleCacheKey(cacheKey, true);
                try {
                    cache = (Cache)this.manager.lookup(cacheRole);
                    cache.remove(key);
               
                    key = new SimpleCacheKey(cacheKey, false);
                    cache.remove(key);
                } catch (Exception ex) {
                    if (this.getLogger().isDebugEnabled()) {
                        getLogger().debug("Exception while trying to remove entry "+cacheKey+" from Cache with role " + cacheRole, ex);
                    }
                } finally {
View Full Code Here

                    Map objectModel,
                    String src,
                    Parameters par
    ) throws Exception {
        final String cacheRole = par.getParameter("cache-role", Cache.ROLE);
        Cache cache = null;

        try {
            cache = (Cache)this.manager.lookup(cacheRole);
            cache.clear();
            return EMPTY_MAP;
        } catch (Exception ex) {
          if (this.getLogger().isDebugEnabled()) {
                getLogger().debug("Exception while trying to clear Cache with role " + cacheRole, ex);
            }
View Full Code Here

                    SourceResolver resolver,
                    Map objectModel,
                    String src,
                    Parameters par
    ) throws Exception {
        Cache cache = (Cache)this.manager.lookup(Cache.ROLE);
        if (cache instanceof EventAwareCacheImpl) {
            Request request = ObjectModelHelper.getRequest(objectModel);
            String eventName = par.getParameter("event");
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Configured for cache event named: " + eventName);
View Full Code Here

TOP

Related Classes of org.apache.cocoon.caching.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.