maidsafe / lru_time_cache

LRU cache settable via size or time to live
BSD 3-Clause "New" or "Revised" License
104 stars 46 forks source link

Lru time cache should have a more standard API #66

Closed canndrew closed 8 years ago

canndrew commented 8 years ago

It's odd that LruTimeCache has a method to clone all it's elements out into a Vec. Standard library collections don't have methods like this. To clone a HashMap into a Vec you'd write:

my_hash_map.iter().map(|(k, v)| (k.clone(), v.clone())).collect()

Although if someone did this in practice (rather than just using the iterator) they'd probably be doing something wrong.

LruTimeCache's API should be changed to mirror that of HashMap as closely as is appropriate.

dirvine commented 8 years ago

!00% agree here. [EDIT] Only adding the iter() should not reset any last seen time

canndrew commented 8 years ago

I just noticed that the TODO list in the README already says this.

andresilva commented 8 years ago

There's now a method peek_iter which returns an iterator (that doesn't update timestamps), so I think this can be closed.

afck commented 8 years ago

Thank you, @andrebeat! With #77 merged, I'm closing this now.