My question is does my code above ensure these two operations (put cache and add lru) appear atomic to the clean task?
yes (assuming cleaning task is in different thread)
And what should I put in XXX?
the same cache object for example: synchronized (cache) {
a the synchronization should happen on the same lock (object)
you can also explore other atomic classes in java if they could be useful in your case: atomic package