#312 Thread-Safe Array Cache

Companies:
Ozon
Themes:
JavaConcurrencyPractice

Implement a thread-safe cache for an array of N integers. The put() method accepts a Map<Integer, Integer>, where the keys are array indexes and the values are new values for the corresponding array cells. The get() method accepts a list of indexes and returns the values of the corresponding cells. A cache consumer must not receive an inconsistent state when using get():

Java
interface Cache {
    void put(Map<Integer, Integer> batch);
    List<Integer> get(List<Integer> indicies);
}

class ThreadsafeCache implements Cache {
    ...
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in