LRU Cache with a static variable for garbage value
Is it a good practice to have such a static variable just for garbage values?


Maybe not:


garbage_val is a Value, so if you return it, then the caller doesn't know whether the get succeeded.
If garbage_val is supposed to be a magic number (an impossible Value), different users of the class might want different magic numbers ... so why isn't garbage_val an instance member instead of a static member?
Normally container classes expect the caller to check that iterator != end() before dereferencing the iterator.


Instead, the following methods might be appropriate:

// throws an exception if key does exist.
Value get(Key key) { ... }
// tests whether key exists: use this before calling get.
bool contains(Key key) { ... }
// return true and initializes value iff key exists.
// if key doesn't exist then valueOut is not initialized. 
bool tryGet(Key key, Value&amp; valueOut) { ... }