Rest API Java keep in memory last 10 minutes requests -


i want develop rest api keeps in memory number of requests done @get in last 10 minutes. in way when request how many requests has been done in last 10 min, api answers me object in memory keeping requests last 10 minutes.

is possible? possibility keep arraylist of request , loop , check if in time interval, not want loop requests.

you can use guava loading cache purpose. can configure remove entries after 10 minutes.

loadingcache<key, value> cache = cachebuilder.newbuilder()     .expireafterwrite(10, timeunit.minutes) 

when getting number of elements in cache can cache.asmap().size(), (cache.size() has better performance gives approximate count).

note: if app running on several nodes, need distributed cache (which loadingcache not).


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -