Question

I saw that you can atomically increment a value in IronCache, but what if you have many IronWorkers trying to put a value into a single cache key? Would it be better to put those value updates on a Message Queue in order to synchronize updates to the cache or is there another idiomatic way?

Was it helpful?

Solution

There is currently no idiomatic way to update a non-integer Cache item without provoking the race condition gods. There are a lot of different hacks to get around the limitation, but your MQ solution (assuming only one worker is writing the changes) is probably your best bet.

We are aware of the shortcoming, and we're working on a fix, but we have nothing to announce at this time.

OTHER TIPS

One way to do this would be to split up your value into multiple cache entries. Say you have your json hierarchy:

{
    "x": "y",
    "sub1": {
        "a": "b"
    },
    "sub2": {
        "c": "d"
    }
}

Change it to:

{
    "x": "y",
    "sub1": "cache_key_a",
    "sub2": "cache_key_b"
}

Then in cache_key_a:

{
    "a": "b"
}

And do the same for cache_key_b and so on. Would that solve your problem?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top