Skip to content

Cache Aside pattern #440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
iluwatar opened this issue Jul 2, 2016 · 2 comments
Closed

Cache Aside pattern #440

iluwatar opened this issue Jul 2, 2016 · 2 comments
Milestone

Comments

@iluwatar
Copy link
Owner

iluwatar commented Jul 2, 2016

https://msdn.microsoft.com/en-us/library/dn589799.aspx

This pattern could be incorporated into https://github.com/iluwatar/java-design-patterns/tree/master/caching example.

@christofferh
Copy link
Contributor

Thanks for an excellent project, I thought I should contribute something back and this one seemed like a low-hanging fruit.

Would it make sense to simply add two helper methods in AppManager, e.g. saveAside and findAside

private static void saveAside(UserAccount userAccount) {
    DbManager.updateDb(userAccount);
    CacheStore.invalidate(userAccount.getUserId());
}

and then either delegate CacheStore.(get,set,invalidate) to cache

public static void invalidate(String userId) {
    cache.invalidate(userId);
}

or simply expose cache with a CacheStore.getCache() getter?

And then add a new case:

public static void save(UserAccount userAccount) {
    if (cachingPolicy == CachingPolicy.THROUGH) {
      CacheStore.writeThrough(userAccount);
    } else if (cachingPolicy == CachingPolicy.AROUND) {
      CacheStore.writeAround(userAccount);
    } else if (cachingPolicy == CachingPolicy.BEHIND) {
      CacheStore.writeBehind(userAccount);
    } else if (cachingPolicy == CachingPolicy.ASIDE) {
      saveAside(userAccount);
}

Would that make sense, @iluwatar?

@iluwatar
Copy link
Owner Author

@christofferh the plan looks reasonable. Just create a pull request and we'll review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants