mirror of
https://github.com/ltcptgeneral/cs239-caching.git
synced 2025-04-01 20:33:26 +00:00
Merge branch 'main' of https://github.com/ltcptgeneral/cs239-caching
This commit is contained in:
commit
1c30154aa7
5
app/cache/tiered_cache.py
vendored
5
app/cache/tiered_cache.py
vendored
@ -21,6 +21,11 @@ class TieredCache(BaselineCache):
|
||||
f = open(self.l2_map[key], "r")
|
||||
v = f.read()
|
||||
f.close()
|
||||
|
||||
# we will also preemptively return the value from l1 to l2:
|
||||
del self.l2_map[key]
|
||||
self.put(key, v)
|
||||
|
||||
return v
|
||||
else: # otherwise its a cache miss and return None
|
||||
return None
|
||||
|
@ -1,7 +1,8 @@
|
||||
import os
|
||||
import yaml
|
||||
import sys
|
||||
|
||||
CONFIG_FILE = "config.yaml"
|
||||
CONFIG_FILE = sys.argv[1]
|
||||
|
||||
def load_config():
|
||||
with open(CONFIG_FILE, "r") as f:
|
||||
|
4
app/config_baseline.yaml
Normal file
4
app/config_baseline.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
cache_strategy: "Baseline" # Change this to "Prefetch" or "Tiered" or "Seive"
|
||||
cache_limit: 10
|
||||
l2_cache_limit: 100
|
||||
db_file: "llmData_sns.json" # Change this to the name of any json file within the "database/datastore" folder
|
4
app/config_seive.yaml
Normal file
4
app/config_seive.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
cache_strategy: "Seive" # Change this to "Prefetch" or "Tiered" or "Seive"
|
||||
cache_limit: 10
|
||||
l2_cache_limit: 100
|
||||
db_file: "llmData_sns.json" # Change this to the name of any json file within the "database/datastore" folder
|
4
app/config_tiered.yaml
Normal file
4
app/config_tiered.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
cache_strategy: "Tiered" # Change this to "Prefetch" or "Tiered" or "Seive"
|
||||
cache_limit: 10
|
||||
l2_cache_limit: 100
|
||||
db_file: "llmData_sns.json" # Change this to the name of any json file within the "database/datastore" folder
|
@ -11,12 +11,16 @@ app = FastAPI()
|
||||
|
||||
# Initialize cache based on strategy from config.yaml or environment variable
|
||||
if CACHE_STRATEGY == "Baseline":
|
||||
print("Using baseline cache strategy")
|
||||
cache = BaselineCache(limit=CACHE_LIMIT)
|
||||
elif CACHE_STRATEGY == "Prefetch":
|
||||
print("Using prefetch cache strategy")
|
||||
cache = PrefetchCache(limit=CACHE_LIMIT)
|
||||
elif CACHE_STRATEGY == "Tiered":
|
||||
print("Using tiered cache strategy")
|
||||
cache = TieredCache(limit=CACHE_LIMIT, l2_limit=L2_CACHE_LIMIT)
|
||||
elif CACHE_STRATEGY == "Seive":
|
||||
print("Using seive cache strategy")
|
||||
cache = SeiveCache(limit=CACHE_LIMIT)
|
||||
else:
|
||||
raise ValueError(f"Invalid CACHE_STRATEGY: {CACHE_STRATEGY}")
|
||||
|
Loading…
x
Reference in New Issue
Block a user