Last active
August 7, 2017 19:19
-
-
Save phillipuniverse/80bbef83aeede059df0c98a4a40b3708 to your computer and use it in GitHub Desktop.
Invalidate cache for an entity in Broadleaf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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