From 7ec62efb9da433b679a924b26902b72e46371a24 Mon Sep 17 00:00:00 2001 From: Jay Hutchinson Date: Sat, 5 May 2018 18:40:02 -0500 Subject: Added len() method to WriteBackCacheManager. --- README.txt | 7 +++++++ pylru.py | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/README.txt b/README.txt index f37c9cc..3c84aa9 100644 --- a/README.txt +++ b/README.txt @@ -183,6 +183,13 @@ Similar to the WriteThroughCacheManager class except write-back semantics are us cached.size(x) # Changes the size of the cache. x MUST be greater than # zero. Returns the new size x. + x = len(cached) # Returns the number of items stored in the store. + # + # WARNING - This method calls sync() internally. If + # that has adverse performance effects for your + # application, you may want to avoid calling this + # method frequently. + cached.clear() # Remove all items from the store and cache. cached.sync() # Make the store and cache consistent. Write all diff --git a/pylru.py b/pylru.py index 0a9bf11..1b5bb88 100644 --- a/pylru.py +++ b/pylru.py @@ -370,6 +370,10 @@ class WriteBackCacheManager(object): def size(self, size=None): return self.cache.size(size) + def len(self): + self.sync() + return len(self.store) + def clear(self): self.cache.clear() self.dirty.clear() -- cgit v1.2.1