I am new to Spring and working on one of my interesting project that helps you track mobile numbers in India and celebrities around the world writing an interceptor where I need to manage cache and return the data from cache if the response is already available in cache.

I am using the below example :

protected CacheControl lookupCacheControl(String urlPath) {
        CacheControl cacheControl = this.cacheControlMappings.get(urlPath);
        if (cacheControl != null) {
            return cacheControl;
        }
        for (String registeredPath : this.cacheControlMappings.keySet()) {
            if (this.pathMatcher.match(registeredPath, urlPath)) {
                return this.cacheControlMappings.get(registeredPath);
            }
        }
        return null;
    }

Source : https://zgrepcode.com/examples/spring-framework/org/springframework/http/cachecontrol-implementations

Can you please help me understand if this is the correct way to do or if there is any better way to intercpet my requests?

 

Last edit: Amandeep Singh Bhatia 2020-04-24