Skip to content

Instantly share code, notes, and snippets.

@pmuir
Forked from struberg/selfinterception
Created October 15, 2014 10:58
Show Gist options
  • Save pmuir/3c553ceef722c2e21c0c to your computer and use it in GitHub Desktop.
Save pmuir/3c553ceef722c2e21c0c to your computer and use it in GitHub Desktop.
@ApplicationScoped
public class CountryService {
private @Inject Cache<String, Country> cache;
private @Inject Self<CountryService> self;
public Country getByIsoA3(String isoA3) {
Country ctry = cache.get(isoA3);
if (ctry == null) {
ctry = self.get().fillCacheFromDb(isoA3);
}
return ctry;
}
@Transactional
Country fillCacheFromDb(String isoA3) {
transactionally load from db...
and fill cache
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment