chrisdone/tryhaskell — pull request #27 by zudov (2014-11-15 16:27:08+00:00)
Title: Store cached expression in LRUCache

Previously evaluated expressions were stored in HashMap which was
emptied once in an hour by `expireCache` thread.

I propose a better solution which uses `Data.Cache.LRU.IO` from `lrucache` package.

Pros:
- Cache becomes more effective as its not flushed completely each hour
- No need for expiring thread
- Harder to maliciously make the server run out-of-memory, however I am not sure
if that was possible before
- Less code

Cons:
- Lookup and insertion time should take insignificantly longer as:
1. LRUCache uses `Data.Map` underneath, if I understand correctly we
get O(log(n)), instead of O(n) as it was with HashMap
2. It has to check if the limit was reached and pop elements
accordingly
- Memory usage per element is slightly higher as there is a need to keep
track of when it was used
- additional dependency

LFU cache would suit better, but I couldn't find haskell implementation (I am
thinking about implementing it myself).

What do you think?