Questions tagged [lru]

LRU is a family of caching algorithms, where LRU stands for least recently used.

LRU is a family of caching algorithms, where LRU stands for least recently used. As the name implies, a cache discards the least recently used items from the cache, when the contents exceed a certain threshold. In this algorithm, writes are quite expensive, as you always need to write the change the usage information when you use an item.

More information at Wikipedia.

304 questions
18
votes
1 answer

Memory-aware LRU caching in Python?

I'm using Python 3's builtin functools.lru_cache decorator to memoize some expensive functions. I would like to memoize as many calls as possible without using too much memory, since caching too many values causes thrashing. Is there a preferred…
Will
  • 4,241
  • 4
  • 39
  • 48
15
votes
3 answers

Configure lru_cache for class and static methods

I am trying to use lru_cache in Python3 to speed up common queries into our Salesforce database. Below is the relevant code that is supposed to a) convert non-hashable arguments to hashable ones, and b) enable the LRU cache for those…
Nicholas Tulach
  • 1,023
  • 3
  • 12
  • 35
15
votes
1 answer

LRU with Caffeine

I'm trying to use Caffeine as LRU cache, so entries that were added first will be evicted first. Ran this code: final Cache map = Caffeine.newBuilder() .maximumSize(10) .initialCapacity(10) …
bgme_one
  • 295
  • 1
  • 3
  • 9
14
votes
2 answers

LRUCache in Scala?

I know Guava has an excellent caching library but I am looking for something more Scala/functional friendly where I can do things like cache.getOrElse(query, { /* expensive operation */}) . I also looked at Scalaz's Memo but that does not have lru…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
13
votes
3 answers

ConcurrentModificationException when updating stored Iterator (for LRU cache implementation)

I am trying to implement my own LRU cache. Yes, I know that Java provides a LinkedHashMap for this purpose, but I am trying to implement it using basic data structures. From reading about this topic, I understand that I need a HashMap for O(1)…
stackoverflowuser2010
  • 38,621
  • 48
  • 169
  • 217
13
votes
1 answer

what is sequential flooding?

This might be simple, but I can't get my head around it. Can anyone give me an example of sequential flooding? In the textbook I am reading and in Internet sources it is stated When the number of buffer frames is less than the pages in file, this…
WannaBeCoder
  • 1,280
  • 2
  • 17
  • 40
13
votes
2 answers

Will the LRU delete entries that have not been used for some amount of time?

When in memcache the available memory is full, memcache uses the LRU (last recently used) algorithm to free memory. My question is will the LRU Algorithm rather delete entries that have not been used for some amount of time (last recently used) than…
zaphod1984
  • 836
  • 2
  • 7
  • 22
12
votes
2 answers

Sizing LRU Cache according to device capabilities and free memory

I'm thinking about implementing the first layer of my caching in an Android app. I was considering SoftReferences to surely avoid OOM exceptions, but since there are many articles about how Android frees these up "too soon", I decided to look into…
user289463
  • 2,804
  • 3
  • 20
  • 21
12
votes
1 answer

Android LruCache (Android 3.1) thread safety

Is the new Android class LruCache thread safe? The java doc says: This class is thread-safe. Perform multiple cache operations atomically by synchronizing on the cache: synchronized (cache) { if (cache.get(key) == null) { …
dnkoutso
  • 6,041
  • 4
  • 37
  • 58
12
votes
1 answer

How does Python's OrderedDict remember elements inserted?

How does OrderedDict in Python remember all the order of the elements? What is the performance overhead? For problems like implementing LRU, I found this really powerful and very simple to implement, but what is the performance gain here? How does…
python
  • 4,403
  • 13
  • 56
  • 103
12
votes
5 answers

Standard implementation of an LRU Cache

I'm building an application with Swift and I'd like to use an LRU Cache in my application. I've implemented a simple LRUCache in Swift but then I figured that since it already ships with Dictionary and Array collections I might be…
Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504
11
votes
4 answers

Python: building an LRU cache

I have around 6,00,000 entries in MongoDB in the following format: feature:category:count where feature could be any word, category is positive or negative, and count tells how many times a feature occurred in a document for that category. …
daydreamer
  • 87,243
  • 191
  • 450
  • 722
11
votes
2 answers

Clear all lru_cache in Python

I have functions in python that have caches with lru_cache e.g. @lru_cache(maxsize=None) def my_function(): ... While i can individually clear the caches with e.g. my_function.cache_clear() is there any way of clearing the caches of every…
kyrenia
  • 5,431
  • 9
  • 63
  • 93
11
votes
2 answers

LinkedHashSet to implement LRU

I want to remove the oldest member of a LinkedHashSet , I know that there's a removeEldestEntry method that I have to override (Java doc for removeEldestEntry ), but I guess that I have to define initial capacity and load factor which I don't care…
Arian
  • 7,397
  • 21
  • 89
  • 177
10
votes
7 answers

Least Recently Used cache using C++

I am trying to implement LRU Cache using C++ . I would like to know what is the best design for implementing them. I know LRU should provide find(), add an element and remove an element. The remove should remove the LRU element. what is the best…
brett
  • 5,379
  • 12
  • 43
  • 48
1
2
3
20 21