I don't think you can do this directly. Even if you could, it would be a bit ugly. However, you can generate a unique request identifier (or even - use the session id, but careful with multiple tabs), and pass that to each processing thread. Then the aspect can use that id as the key to the cache. The cache itself will also be singleton, but there will be Map<String, X>
, where String
is the ID and X is your cached result.
To make things easier to handle, you can have @Async
methods (rather than manually spawning threads), and each @Async
method can have the cache id passed as its first parameter.
(Of course, your asynchronous methods should return Future<Result>
so that you can collect their results in the request thread)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…