Package javax.ws.rs.core

Examples of javax.ws.rs.core.CacheControl


        checkNotNull(cacheExtensions);
        _cacheExtensions = ImmutableMap.copyOf(cacheExtensions);
    }

    public CacheControl buildCacheControl() {
        CacheControl cacheControl = new CacheControl();
        cacheControl.setNoTransform(false); // Default is true

        if (_maxAge.isPresent()) {
            cacheControl.setMaxAge((int) _maxAge.get().toSeconds());
        }

        if (_sharedMaxAge.isPresent()) {
            cacheControl.setSMaxAge((int) _maxAge.get().toSeconds());
        }

        if (_privateFields.size() > 0) {
            cacheControl.setPrivate(true);
            cacheControl.getPrivateFields().addAll(_privateFields);
        }

        if (_noCacheFields.size() > 0) {
            cacheControl.setNoCache(true);
            cacheControl.getNoCacheFields().addAll(_noCacheFields);
        }

        for (CacheControlFlag flag : _flags) {
            switch (flag) {
                case NO_CACHE:
                    cacheControl.setNoCache(true);
                    break;

                case NO_STORE:
                    cacheControl.setNoStore(true);
                    break;

                case MUST_REVALIDATE:
                    cacheControl.setMustRevalidate(true);
                    break;

                case PROXY_REVALIDATE:
                    cacheControl.setProxyRevalidate(true);
                    break;

                case NO_TRANSFORM:
                    cacheControl.setNoTransform(true);
                    break;

                case PRIVATE:
                    cacheControl.setPrivate(true);
                    break;

                case PUBLIC:
                    // public is not directly supported by the CacheControl object, so use extension map
                    cacheControl.getCacheExtension().put("public", "");
                    break;

                default:
                    checkState(false, "Unhandled cache control flag: " + flag);
                    break;
            }
        }

        // Although the docs don't state it explicitly, both null and empty string get converted to a bare directive
        // for cache extensions.
        cacheControl.getCacheExtension().putAll(_cacheExtensions);
        return cacheControl;
    }
View Full Code Here


     *
     * @param response the response context
     * @return true if the response may be cached, false if the response must not be cached
     */
    private static boolean isResponseCacheable(CacheResponseContext response) {
        CacheControl cacheControl = response.getCacheControl();

        return !cacheControl.isNoStore() &&
                !cacheControl.isNoCache() &&
                !cacheControl.isPrivate() &&
                response.getSharedCacheMaxAge() > 0;
    }
View Full Code Here

            if (requestCacheControl.getMinFresh() >= 0 && freshness < requestCacheControl.getMinFresh()) {
                return false;
            }

            if (requestCacheControl.getMaxStale() >= 0) {
                CacheControl responseCacheControl = response.getCacheControl().orNull();
                boolean responseMustRevalidate = responseCacheControl != null && (responseCacheControl.isProxyRevalidate() || responseCacheControl.isMustRevalidate());

                if (!responseMustRevalidate) {
                    return freshness >= -requestCacheControl.getMaxStale();
                }
            }
View Full Code Here

        checkNotNull(cacheExtensions);
        _cacheExtensions = ImmutableMap.copyOf(cacheExtensions);
    }

    public CacheControl buildCacheControl() {
        CacheControl cacheControl = new CacheControl();
        cacheControl.setNoTransform(false); // Default is true

        if (_maxAge.isPresent()) {
            cacheControl.setMaxAge((int) _maxAge.get().toSeconds());
        }

        if (_sharedMaxAge.isPresent()) {
            cacheControl.setSMaxAge((int) _maxAge.get().toSeconds());
        }

        if (_privateFields.size() > 0) {
            cacheControl.setPrivate(true);
            cacheControl.getPrivateFields().addAll(_privateFields);
        }

        if (_noCacheFields.size() > 0) {
            cacheControl.setNoCache(true);
            cacheControl.getNoCacheFields().addAll(_noCacheFields);
        }

        for (CacheControlFlag flag : _flags) {
            switch (flag) {
                case NO_CACHE:
                    cacheControl.setNoCache(true);
                    break;

                case NO_STORE:
                    cacheControl.setNoStore(true);
                    break;

                case MUST_REVALIDATE:
                    cacheControl.setMustRevalidate(true);
                    break;

                case PROXY_REVALIDATE:
                    cacheControl.setProxyRevalidate(true);
                    break;

                case NO_TRANSFORM:
                    cacheControl.setNoTransform(true);
                    break;

                case PRIVATE:
                    cacheControl.setPrivate(true);
                    break;

                case PUBLIC:
                    // public is not directly supported by the CacheControl object, so use extension map
                    cacheControl.getCacheExtension().put("public", "");
                    break;

                default:
                    checkState(false, "Unhandled cache control flag: " + flag);
                    break;
            }
        }

        // Although the docs don't state it explicitly, both null and empty string get converted to a bare directive
        // for cache extensions.
        cacheControl.getCacheExtension().putAll(_cacheExtensions);
        return cacheControl;
    }
View Full Code Here

     *
     * @param response the response context
     * @return true if the response may be cached, false if the response must not be cached
     */
    private static boolean isResponseCacheable(CacheResponseContext response) {
        CacheControl cacheControl = response.getCacheControl();

        return !cacheControl.isNoStore() &&
                !cacheControl.isNoCache() &&
                !cacheControl.isPrivate() &&
                response.getSharedCacheMaxAge() > 0;
    }
View Full Code Here

            if (requestCacheControl.getMinFresh() >= 0 && freshness < requestCacheControl.getMinFresh()) {
                return false;
            }

            if (requestCacheControl.getMaxStale() >= 0) {
                CacheControl responseCacheControl = response.getCacheControl().orNull();
                boolean responseMustRevalidate = responseCacheControl != null && (responseCacheControl.isProxyRevalidate() || responseCacheControl.isMustRevalidate());

                if (!responseMustRevalidate) {
                    return freshness >= -requestCacheControl.getMaxStale();
                }
            }
View Full Code Here

        return _cacheControl;
    }

    public Optional<DateTime> getExpires() {
        if (_expires == null) {
            CacheControl cacheControl = getCacheControl().orNull();

            _expires = Optional.absent();

            if (cacheControl != null) {
                int maxAge = CacheControlUtils.getSharedCacheMaxAge(cacheControl);
View Full Code Here

                    LOG.debug("Failed to parse cache-control header: value='{}'", headerValues, ex);
                }
            }

            if (_cacheControl == null) {
                _cacheControl = new CacheControl();
            }
        }

        return _cacheControl;
    }
View Full Code Here

        URI pageUri = uriInfo.getBaseUriBuilder()
                .path("system/console/usermanagement").build();

        // header Cache-control: no-cache, just in case intermediaries are
        // holding onto old stuff
        CacheControl cc = new CacheControl();
        cc.setNoCache(true);

        //showSystem();

        // see other my not be the best response, but does seem the best given
        // the jax-rs things available
View Full Code Here

        URI pageUri = uriInfo.getBaseUriBuilder()
                .path("system/console/usermanagement").build();

        // header Cache-control: no-cache, just in case intermediaries are
        // holding onto old stuff
        CacheControl cc = new CacheControl();
        cc.setNoCache(true);

        //showSystem();

        // see other my not be the best response, but does seem the best given
        // the jax-rs things available
View Full Code Here

TOP

Related Classes of javax.ws.rs.core.CacheControl

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.