2

I trying to implement a write-back cache. I'm trying to use soft referenes, but I'm having troubles performing the post-mortum write-back because the reference is cleared before it's added to the gcQueue and thus I don't have access to the referent object.

Solutions?

1 Answer 1

2

You can try Guava's Mapmaker.

Example:

final ConcurrentMap<Long, Integer> cache = new MapMaker()
        .softValues().expiration(20,TimeUnit.MINUTES)
        .makeComputingMap(new Function<Long, Integer>() {
              @Override
            public Integer apply(Long arg0) {
                return null;
            }
            });

SO Questions on MapMaker :

Alternative option :

Use Supplier class's memoizeWithExpiration which is also part of guava library.

Sign up to request clarification or add additional context in comments.

1 Comment

I really can't see how it helps with the write-back.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.