this pattern is referred to as a memoizer. i blogged about it here: http://javathink.blogspot.com/2008/09/what-is-memoizer-and-why-should-you.html
there's also a nice implementation on google code: http://code.google.com/p/concurrentlinkedhashmap/wiki/SelfPopulatingCache On Tue, Feb 17, 2009 at 9:10 AM, Alen Vrečko <[email protected]> wrote: > > Hi, > > I had similar problem. In the end I just went with LinkedHashMap (LRU) > with synchronization and keyed on username. MapMaker is nice but not > my choice for LRU. > > What do you key on? If this is a pure method it could be the > arguments, if not some different criteria applies? > > Cheers, > Alen > > On Feb 17, 9:25 am, Andreas <[email protected]> wrote: > > hi! > > > > i will need to use a simplistic caching on some methods in my code. > > for example, i do geocoding, route planning, REST request, etc.. and i > > want to avoid doing the exact same requests more than once every few > > seconds. > > > > this happens in multiple threads both in batch processes and in > > response to http requests, so its a classic cross-cutting concern. > > > > of course i could implement a simplistic implementation of cached > > methods, but i thought maybe other people have the same problem. im > > thinking of doing a @Cached(maxObjects=5000, lifetime=MILLIS_PER_DAY) > > annotation, with two hashMaps to store the data. maybe also > > weakHashMap in addition? > > > > in spring this is done via cache provider, which is quite flexible and > > also allows for cluster-aware caching. in my case a simple cache for > > maximum ~5000 objects with a maximum lifetime of 1 day would be > > sufficient. > > > > has anyone implemented something similar? i want to avoid reinventing > > the wheel - though i like to learn more about wheels. > > > > best regards > > Andreas > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/google-guice?hl=en -~----------~----~----~----~------~----~------~--~---
