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

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Implementing HTTP Caching in Default Resources

Implementing HTTP Caching in Default Resources

If a default resource does not have HTTP caching, you must extend the resource by following the instruction to extend a Helix resource to enable caching. You must also create an Info prototype.
Note: Do not add the @PrototypeExtension annotation to the Info prototype.
To enable HTTP caching for a new resource, create a prototype that implements the Info interface of the resource.

For the NavigationResource, create a 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;
	}
}

Overriding HTTP Caching in a Default Resource

To override the max-age for a default resource, extend the Info prototype for the resource and provide the new value.
For the NavigationResource, to override the max-age, do as in the following example:
/**
 * Navigation prototype for Info operation.
 */
@PrototypeExtension
public class InfoExtNavigationPrototype implements NavigationResource.Info {

	private static final Single<ResourceInfo> INFO_SINGLE = Single.just(ResourceInfo.builder()
			.withMaxAge(300)
			.build());

	@Override
	public Single<ResourceInfo> onInfo() {
		return INFO_SINGLE;
	}
}