3

If I create a library in Java, that is cache but auto-refreshes your data on regular intervals, totally configurable in terms of frequency of auto refresh and number of background threads used so as to reduce latency when you actually need data; will it be useful?

So currently, Guava cache has the feature to refresh only after you actually try to read data, which can actually be troublesome for a high QPS system.

I personally had this use-case, and wondered if there's anything existing (couldn't find, so wrote for my personal use case) and if it is an actual use case worth a library.

Comments
  • 1
    Afaik multiple solutions exists.

    Most common is Executor scheduling...

    The trouble in Java starts when Types kick in.

    Most reimplement a simple data type like Map or sth and then add a fully generic typed solution which has an executor behind it to configure interval / parallel execution.

    A library sounds good imho, most of the times a lot of corner cases exist.

    From the joys of synchronicity to problems regarding immutability of content (you shouldn't be able to modify the cached data in my opinion) etc cetera.

    You'll definitely learn a lot about Javas execution scheduler, which is a complex beast.
  • 0
    @IntrusionCM
    So I have written a basic implementation on top of Google commons, by making use of Java generics and reflection and now I'm trying to think of cases to handle, or edge cases.

    A lot of it is config driven, with defaults.

    There is basically two type of scheduling options I could think of, although I wasn't which one is better, so added feature for both.
    1) Schedule each key independently for auto refresh
    2) Schedule all the keys together into a thread pool on regular intervals

    Can you come up with some sample problems the library should handle?
    I'll upload it to github as soon as I'm able to copy it in some other laptop (currently it's on my work laptop)
  • 0
  • 0
  • 2
    Have you seen the Caffeine Java caching library? It's pretty well established, and it supports time based eviction with refreshAfterWrite() (automatically refreshing it a certain time interval after it's loaded), which sounds like could be what you're after.

    By all means create your own thing - not trying to dissuade you from that - but it may not be as unique as you think, unfortunately. If Caffeine doesn't do what you want though, it may be more rewarding and a better learning experience to raise a PR on their library, rather than implementing your own.
  • 0
    @AlmondSauce doesn't refreshAfterWrite refreshes when the next that key is accessed?
  • 0
    @BugsBuggy I think that's "expireAfterWrite()", but it's a long time since I've used caffeine so I could be getting muddled.
  • 3
    @AlmondSauce well, I looked up.
    Caffeine apparently does exactly what I wanted, with pretty much the same concept (asynchronous refresh and LRU based eviction)... Damn, finally I thought I'll have a good personal project that people can actually use, there goes my dream 😰
  • 1
    @BugsBuggy I know the feeling, it's damn hard finding something new and useful!
  • 0
    @AlmondSauce well, apparently not. Caffeine also updates it only when it is accessed.
    Now, all I have to do is understand the feasibility. I have calculated the numbers, but I have such less experience with scaled out systems, that I am unable to figure it out.
Add Comment