Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. The Developer Center continues to support Commerce 6.13.0 through 7.4.1.Visit new site

Implementing HTTP Caching in New Resources

Implementing HTTP Caching in New Resources

For a new Helix resource, to implement HTTP caching by providing the Cache-Control header , you must create a new Helix prototype that implements the Info interface of the resource.

  1. Create the new resource.
  2. Create a Helix prototype to implement the Info interface.
    For NavigationResource, create an InfoNavigationPrototype that implements the NavigationResource.Info interface as in the following example:
    /**
     * Navigation prototype for Info operation.
     */
    public class InfoNavigationPrototype implements NavigationResource.Info {
    
    	private static final Single<ResourceInfo> INFO_SINGLE = Single.just(ResourceInfo.builder()
    			.withMaxAge(NavigationsResourceConstants.MAX_AGE)
    			.build());
    
    	@Override
    	public Single<ResourceInfo> onInfo() {
    		return INFO_SINGLE;
    	}
    }
    In the prototype, a ResourceInfo is built and the max-age for the resource is returned.