Skip to content

Commit ee76642

Browse files
Aseem JainAseem Jain
Aseem Jain
authored and
Aseem Jain
committed
Cache
1 parent ce6428d commit ee76642

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

NOTES.MD

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
# What is Cache?
3+
A cache is like short-term memory: it has a limited amount of space, but is typically faster than the original data source and contains the most recently accessed items. Caches can exist at all levels in architecture, but are often found at the level nearest to the front end, where they are implemented to return data quickly without taxing downstream levels.
4+
They are used in almost every computing layer: hardware, operating systems, web browsers, web applications, and more.
5+
6+
## Cache invalidation
7+
If the data is modified in the database, it should be invalidated in the cache; if not, this can cause inconsistent application behavior.
8+
9+
Write-through cache: Under this scheme, data is written into the cache and the corresponding database simultaneously.
10+
Write-around cache: This technique is similar to write-through cache, but data is written directly to permanent storage, bypassing the cache.
11+
Write-back cache: Under this scheme, data is written to cache alone, and completion is immediately confirmed to the client.
12+
13+
## Cache eviction policies
14+
Following are some of the most common cache eviction policies:
15+
First In First Out (FIFO): The cache evicts the first block accessed first without any regard to how often or how many times it was accessed before.
16+
Least Recently Used (LRU): Discards the least recently used items first.
17+
Least Frequently Used (LFU): Counts how often an item is needed. Those that are used least often are discarded first.
18+
Time To Live (TTL): Data is remains in the cache for specific time like 300 sec and deleted after that. It can be renewed upon usage if needed.
19+
Random Replacement (RR): Randomly selects a candidate item and discards it to make space when necessary.
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
@Author: Aseem Jain
3+
@Linkedin: https://www.linkedin.com/in/premaseem/
4+
@Github: https://github.com/premaseem/pythonLab/tree/master/challenge
5+
6+
# What is Cache?
7+
A cache is like short-term memory: it has a limited amount of space, but is typically faster than the original data source and contains the most recently accessed items. Caches can exist at all levels in architecture, but are often found at the level nearest to the front end, where they are implemented to return data quickly without taxing downstream levels.
8+
9+
# Following are some of the most common cache eviction policies:
10+
First In First Out (FIFO): The cache evicts the first block accessed first without any regard to how often or how many times it was accessed before.
11+
Least Recently Used (LRU): Discards the least recently used items first.
12+
Least Frequently Used (LFU): Counts how often an item is needed. Those that are used least often are discarded first.
13+
Time To Live (TTL): Data is remains in the cache for specific time like 300 sec and deleted after that. It can be renewed upon usage if needed.
14+
Random Replacement (RR): Randomly selects a candidate item and discards it to make space when necessary.
15+
16+
"""
17+
18+
19+
def sol(n):
20+
return n * 2
21+
22+
23+
test_data = [
24+
(2, 4),
25+
(4, 8),
26+
]
27+
28+
for given, expected in test_data:
29+
assert expected == sol(given)
30+
print(f"Test passed for: given {given} and expected = {expected}")

0 commit comments

Comments
 (0)