On 30/01/12 18:22, Les Hazlewood wrote:
There could be, depending on how long your TTL is. However, this is
easily enough solved IMO using a ThreadLocal implementation that
simulates a local cache:
Look up the object in the ThreadLocal - if its ID matches the DAO ID
argument, return it. If it doesn't match, clear out the ThreadLocal,
look up the session object from the underlying store and then store it
in the ThreadLocal. Also overwrite the ThreadLocal value during a
write operation.
This logic probably will go into Shiro's implementation for 1.3, but
that kind of gives you an idea if you need this right away. (Of
course if you do work on this and you are capable, any patches would
be appreciated!)
What I've done for the meantime, to check things out, is to use EHCache
for my local cache, with a TTL of 1 second. In my 'get' method I first
check to see if the session object exists in the cache and if so, use
it, otherwise I get it from Redis and store it in the local cache. In
the 'put' I put the object in Redis and the local cache as well. Does
this sound right? It looks like it should reduce the network calls by
90%. I'm not sure what you mean by "if its ID matches the DAO ID
argument, return it" above.