Preferred way for using CacheControl

I am new to Spring and 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 : Zgrepcode
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?