Elastic Path Commerce Development

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.