Skip to content

Instantly share code, notes, and snippets.

@phillipuniverse
Last active August 7, 2017 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phillipuniverse/80bbef83aeede059df0c98a4a40b3708 to your computer and use it in GitHub Desktop.
Save phillipuniverse/80bbef83aeede059df0c98a4a40b3708 to your computer and use it in GitHub Desktop.
Invalidate cache for an entity in Broadleaf
@Component
public class SkuInvalidator {
@Autowired
private SystemEventSender eventSender;
public void invalidateSku(Long id) {
SystemEvent event = new SystemEventImpl();
event.setType(EventType.CACHE_INVALIDATION.getType());
event.setEnabled(true);
event.setScopeType(EventScopeType.GLOBAL);
event.setWorkerType(EventWorkerType.ANY);
// comes from the @Cache annotation which denotes the region I am evicting from
addDetail(CacheInvalidationEventDetailType.CACHE_REGION.getType(), "blProducts", event);
// If you have an extension of SkuImpl then you should use the extension as the ENTITY_TYPE
addDetail(CacheInvalidationEventDetailType.ENTITY_TYPE.getType(), SkuImpl.class.getName(), event);
addDetail(CacheInvalidationEventDetailType.IDENTIFIER.getType(), id.toString(), event);
eventSender.sendEvents(Arrays.asList(event));
}
private SystemEventDetail addDetail(String name, String value, SystemEvent event) {
SystemEventDetail detail = new SystemEventDetailImpl();
detail.setEvent(event);
detail.setName(name);
detail.setValue(value);
event.getEventDetails().put(detail.getName(), detail);
return detail;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment