Skip to content

Instantly share code, notes, and snippets.

@yp-palF
Created March 31, 2019 06:02
Show Gist options
  • Save yp-palF/7d9084ba914590169ffdb39b3911081c to your computer and use it in GitHub Desktop.
Save yp-palF/7d9084ba914590169ffdb39b3911081c to your computer and use it in GitHub Desktop.
void saveToCache(Movie movie) {
List<String> cacheableModel = new ArrayList<>();
String cacheKey;
for (Field field : movie.class.getDeclaredFields()) {
if (field.isAnnotationPresent(Cached.class)) {
field.setAccessible(true);
cacheableModel.add(field.get(movie));
}
if (field.isAnnotationPresent(CacheKey.class)) {
cacheKey = field.get(movie).toString();
}
}
cache.save(cacheKey, cacheModel);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment