The learning objectives of this project are:
- What a caching system is
- What FIFO means
- What LIFO means
- What LRU means
- What MRU means
- What LFU means
- What the purpose of a caching system
- What limits a caching system have
Create a class BasicCache
that inherits from BaseCaching
and is a caching system:
- You must use
self.cache_data
- dictionary from the parent classBaseCaching
- This caching system doesn’t have limit
def put(self, key, item):
- Must assign to the dictionary
self.cache_data
theitem
value for the keykey
. - If
key
oritem
isNone
, this method should not do anything.
- Must assign to the dictionary
def get(self, key):
- Must return the value in
self.cache_data
linked tokey
. - If
key
isNone
or if thekey
doesn’t exist inself.cache_data
, returnNone
.
- Must return the value in
Create a class FIFOCache
that inherits from BaseCaching
and is a caching system:
- You must use
self.cache_data
- dictionary from the parent classBaseCaching
- You can overload
def __init__(self):
but don’t forget to call the parent init:super().__init__()
def put(self, key, item):
- Must assign to the dictionary
self.cache_data
the item value for the keykey
. - If
key
oritem
isNone
, this method should not do anything. - If the number of items in
self.cache_data
is higher thatBaseCaching.MAX_ITEMS
:- you must discard the first item put in cache (FIFO algorithm)
- you must print
DISCARD:
with thekey
discarded and following by a new line
- Must assign to the dictionary
def get(self, key):
- Must return the value in
self.cache_data
linked to key. - If
key
isNone
or if thekey
doesn’t exist inself.cache_data
, returnNone
.
- Must return the value in
Create a class LIFOCache
that inherits from BaseCaching
and is a caching system:
- You must use
self.cache_data
- dictionary from the parent class BaseCaching - You can overload
def __init__(self):
but don’t forget to call the parent init:super().__init__()
def put(self, key, item):
- Must assign to the dictionary
self.cache_data
theitem
value for the keykey
. - If
key
oritem
isNone
, this method should not do anything. - If the number of items in
self.cache_data
is higher thatBaseCaching.MAX_ITEMS
:- you must discard the last item put in cache (LIFO algorithm)
- you must print
DISCARD:
with thekey
discarded and following by a new line
- Must assign to the dictionary
def get(self, key):
- Must return the value in
self.cache_data
linked tokey
. - If
key
isNone
or if thekey
doesn’t exist inself.cache_data
, returnNone
- Must return the value in
Create a class LRUCache
that inherits from BaseCaching
and is a caching system:
- You must use
self.cache_data
- dictionary from the parent class BaseCaching - You can overload
def __init__(self):
but don’t forget to call the parent init:super().__init__()
def put(self, key, item):
- Must assign to the dictionary
self.cache_data
theitem
value for the keykey
. - If
key
oritem
isNone
, this method should not do anything. - If the number of items in
self.cache_data
is higher thatBaseCaching.MAX_ITEMS
:- you must discard the least recently used item (LRU algorithm)
- you must print
DISCARD:
with thekey
discarded and following by a new line
- Must assign to the dictionary
def get(self, key):
- Must return the value in
self.cache_data
linked tokey
. - If
key
isNone
or if thekey
doesn’t exist inself.cache_data
, returnNone
- Must return the value in
Create a class MRUCache
that inherits from BaseCaching
and is a caching system:
- You must use
self.cache_data
- dictionary from the parent class BaseCaching - You can overload
def __init__(self):
but don’t forget to call the parent init:super().__init__()
def put(self, key, item):
- Must assign to the dictionary
self.cache_data
theitem
value for the keykey
. - If
key
oritem
isNone
, this method should not do anything. - If the number of items in
self.cache_data
is higher thatBaseCaching.MAX_ITEMS
:- you must discard the most recently used item (MRU algorithm)
- you must print
DISCARD:
with thekey
discarded and following by a new line
- Must assign to the dictionary
def get(self, key):
- Must return the value in
self.cache_data
linked tokey
. - If
key
isNone
or if thekey
doesn’t exist inself.cache_data
, returnNone
- Must return the value in
Create a class LFUCache
that inherits from BaseCaching
and is a caching system:
- You must use
self.cache_data
- dictionary from the parent class BaseCaching - You can overload
def __init__(self):
but don’t forget to call the parent init:super().__init__()
def put(self, key, item):
- Must assign to the dictionary
self.cache_data
theitem
value for the keykey
. - If
key
oritem
isNone
, this method should not do anything. - If the number of items in
self.cache_data
is higher thatBaseCaching.MAX_ITEMS
:- you must discard the least frequency used item (LFU algorithm)
- if you find more than 1 item to discard, you must use the LRU algorithm to discard only the least recently used
- you must print
DISCARD:
with thekey
discarded and following by a new line
- Must assign to the dictionary
def get(self, key):
- Must return the value in
self.cache_data
linked tokey
. - If
key
isNone
or if thekey
doesn’t exist inself.cache_data
, returnNone
- Must return the value in