cac he: Cleared old cache files
All checks were successful
Build Docker / BuildImage (push) Successful in 39s

This commit is contained in:
Nathan Woodburn 2024-12-11 13:31:52 +11:00
parent d231d8b153
commit e4a12396b7
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
18 changed files with 19 additions and 26 deletions

View File

@ -20,19 +20,15 @@ def file_cache(ttl=3600):
def refresh_cache(func, cache_file, cache_key, args, kwargs): def refresh_cache(func, cache_file, cache_key, args, kwargs):
def refresh_loop(): def refresh_loop():
while True: while True:
print(f"Waiting for cache for {func.__name__} to expire...",flush=True) sleep(ttl)
sleep(ttl/2)
try: try:
# Check if the cache is less than half the ttl (wait for half ttl to pass)
if os.path.exists(cache_file): if os.path.exists(cache_file):
with open(cache_file, "r") as f: with open(cache_file, "r") as f:
cached_data = json.load(f) cached_data = json.load(f)
if time() - cached_data["timestamp"] < ttl / 2: if time() - cached_data["timestamp"] < ttl:
print(f"Cache for {func.__name__} is less than half the TTL, skipping refresh.",flush=True)
return return
# Re-compute the result and update the cache # Re-compute the result and update the cache
print(f"Refreshing cache for {func.__name__}...",flush=True)
result = func(*args, **kwargs) result = func(*args, **kwargs)
with open(cache_file, "w") as f: with open(cache_file, "w") as f:
json.dump({"timestamp": time(), "result": result}, f) json.dump({"timestamp": time(), "result": result}, f)
@ -53,7 +49,6 @@ def file_cache(ttl=3600):
# Start a background thread for auto-refresh if it doesn't exist # Start a background thread for auto-refresh if it doesn't exist
if not os.path.exists(cache_file): if not os.path.exists(cache_file):
print(f"Creating cache for {func.__name__} with auto-refresh.",flush=True)
result = func(*args, **kwargs) result = func(*args, **kwargs)
with open(cache_file, "w") as f: with open(cache_file, "w") as f:
json.dump({"timestamp": time(), "result": result}, f) json.dump({"timestamp": time(), "result": result}, f)
@ -67,8 +62,7 @@ def file_cache(ttl=3600):
with open(cache_file, "r") as f: with open(cache_file, "r") as f:
cached_data = json.load(f) cached_data = json.load(f)
# Check if the cache has expired # Check if the cache has expired
if time() - cached_data["timestamp"] < ttl: if time() - cached_data["timestamp"] < (ttl * 2):
print(f"Cache valid for {func.__name__}.",flush=True)
refresh_cache(func, cache_file, cache_key, args, kwargs) refresh_cache(func, cache_file, cache_key, args, kwargs)
return cached_data["result"] return cached_data["result"]
except (IOError, ValueError, KeyError): except (IOError, ValueError, KeyError):

View File

@ -1 +1 @@
{"timestamp": 1733809035.843733, "result": 3685.0} {"timestamp": 1733884155.1054926, "result": 3598.9}

View File

@ -1 +1 @@
{"timestamp": 1733809157.2758396, "result": 1.007} {"timestamp": 1733884280.7491436, "result": 0.991137}

View File

@ -1 +0,0 @@
{"timestamp": 1733446705.0293868, "result": [{"mint": "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh", "balance": 0.00011819, "price": 97423, "value": 11.51442437, "name": "Wrapped BTC (Wormhole)", "symbol": "wbtc"}, {"mint": "jupSoLaHXQiZZTSfEWMTRRgpnyFm8f6sZdosWBjx93v", "balance": 0.039815492, "price": 253.52, "value": 10.094023531840001, "name": "Jupiter Staked SOL", "symbol": "jupsol"}, {"mint": "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs", "balance": 0.00255735, "price": 3851.54, "value": 9.849735819, "name": "Ethereum (Wormhole)", "symbol": "eth"}, {"mint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4", "balance": 2.402337, "price": 4.18, "value": 10.04176866, "name": "Jupiter Perpetuals Liquidity Provider Token", "symbol": "jlp"}]}

View File

@ -1 +1 @@
{"timestamp": 1733809036.2606697, "result": 4.18} {"timestamp": 1733884156.764032, "result": 4.19}

View File

@ -1 +1 @@
{"timestamp": 1733808953.7016218, "result": 691.78} {"timestamp": 1733884155.9249303, "result": 669.29}

View File

@ -1 +1 @@
{"timestamp": 1733809033.8840516, "result": 228.36} {"timestamp": 1733884154.2864244, "result": 228.27}

View File

@ -1 +1 @@
{"timestamp": 1733809097.260591, "result": 3.76} {"timestamp": 1733884278.9056113, "result": 3.66}

View File

@ -1 +1 @@
{"timestamp": 1733809031.4238954, "result": 215.71} {"timestamp": 1733884279.7248404, "result": 214.52}

View File

@ -1 +1 @@
{"timestamp": 1733809097.0826066, "result": 3.9} {"timestamp": 1733884218.3883016, "result": 3.79}

View File

@ -1 +1 @@
{"timestamp": 1733809380.8129568, "result": 523.319974704} {"timestamp": 1733884290.7832794, "result": 524.345950296}

View File

@ -1 +1 @@
{"timestamp": 1733809031.4242568, "result": 0.055512624} {"timestamp": 1733884279.315854, "result": 0.055517624}

View File

@ -1 +1 @@
{"timestamp": 1733799271.6589923, "result": 0.999083} {"timestamp": 1733884217.6712437, "result": 1.001}

View File

@ -1 +1 @@
{"timestamp": 1733809036.7571216, "result": 96471} {"timestamp": 1733884153.469039, "result": 96162}

View File

@ -1 +1 @@
{"timestamp": 1733809383.5021977, "result": [{"mint": "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh", "balance": 0.00056828, "price": 96471, "value": 54.82253988, "name": "Wrapped BTC (Wormhole)", "symbol": "wbtc"}, {"mint": "jupSoLaHXQiZZTSfEWMTRRgpnyFm8f6sZdosWBjx93v", "balance": 0.239815492, "price": 228.36, "value": 54.76426575312, "name": "Jupiter Staked SOL", "symbol": "jupsol"}, {"mint": "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs", "balance": 0.00255735, "price": 3685.0, "value": 9.42383475, "name": "Ethereum (Wormhole)", "symbol": "eth"}, {"mint": "9gP2kCy3wA1ctvYWQk75guqXuHfrEomqydHLtcTCqiLa", "balance": 0.03683279, "price": 691.78, "value": 25.480187466199997, "name": "Binance Coin (Wormhole)", "symbol": "bnb"}, {"mint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4", "balance": 19.88979, "price": 4.18, "value": 83.1393222, "name": "Jupiter Perpetuals Liquidity Provider Token", "symbol": "jlp"}, {"mint": "0x2::sui::SUI", "balance": 0.902850107, "price": 3.76, "value": 3.39471640232, "name": "Sui", "symbol": "sui"}, {"mint": "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", "balance": 22.852920128, "price": 3.9, "value": 89.1263884992, "name": "Volo Staked SUI", "symbol": "vsui"}]} {"timestamp": 1733884278.9088798, "result": [{"mint": "3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh", "balance": 0.00056828, "price": 96162, "value": 54.64694136, "name": "Wrapped BTC (Wormhole)", "symbol": "wbtc"}, {"mint": "jupSoLaHXQiZZTSfEWMTRRgpnyFm8f6sZdosWBjx93v", "balance": 0.239815492, "price": 228.27, "value": 54.74268235884, "name": "Jupiter Staked SOL", "symbol": "jupsol"}, {"mint": "7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs", "balance": 0.00255735, "price": 3598.9, "value": 9.203646915, "name": "Ethereum (Wormhole)", "symbol": "eth"}, {"mint": "9gP2kCy3wA1ctvYWQk75guqXuHfrEomqydHLtcTCqiLa", "balance": 0.03683279, "price": 669.29, "value": 24.6518180191, "name": "Binance Coin (Wormhole)", "symbol": "bnb"}, {"mint": "27G8MtK7VtTcCHkpASjSDdkWWYfoqT6ggEuKidVJidD4", "balance": 19.88979, "price": 4.19, "value": 83.33822010000002, "name": "Jupiter Perpetuals Liquidity Provider Token", "symbol": "jlp"}, {"mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", "balance": 1.0, "price": 1.001, "value": 1.001, "name": "USDC", "symbol": "usdc"}, {"mint": "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", "balance": 22.852920128, "price": 3.79, "value": 86.61256728512001, "name": "Volo Staked SUI", "symbol": "vsui"}, {"mint": "0x2::sui::SUI", "balance": 0.902850107, "price": 3.66, "value": 3.30443139162, "name": "Sui", "symbol": "sui"}]}

View File

@ -1 +1 @@
{"timestamp": 1733809309.7510543, "result": [{"mint": "0x2::sui::SUI", "balance": 0.902850107, "price": 3.76, "value": 3.39471640232, "name": "Sui", "symbol": "sui"}, {"mint": "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", "balance": 22.852920128, "price": 3.9, "value": 89.1263884992, "name": "Volo Staked SUI", "symbol": "vsui"}]} {"timestamp": 1733884278.9084196, "result": [{"mint": "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", "balance": 22.852920128, "price": 3.79, "value": 86.61256728512001, "name": "Volo Staked SUI", "symbol": "vsui"}, {"mint": "0x2::sui::SUI", "balance": 0.902850107, "price": 3.66, "value": 3.30443139162, "name": "Sui", "symbol": "sui"}]}

View File

@ -1 +1 @@
{"timestamp": 1733809208.7161782, "result": 82.815227} {"timestamp": 1733884280.3400621, "result": 82.815227}

View File

@ -1 +1 @@
{"timestamp": 1733809381.9097087, "result": [{"name": "Kamino USDC Lending", "description": "Kamino USDC Lending", "apy": 26.85, "url": "https://app.kamino.finance/lending/reserve/DxXdAyU3kCjnyggvHmY5nAwg5cRbbmdyX3npfDMjjMek/Ga4rZytCpq1unD4DbEJ5bkHeUz9g3oh9AAFEi6vSauXp", "value": 50.01, "updated": "1733790668", "initial": 50, "bought": "1733717057", "type": "Lending"}, {"name": "dYdX MegaVault", "description": "dYdX MegaVault", "apy": 55, "url": "https://dydx.trade/vault", "value": 44.45, "updated": "1733790645", "initial": 44, "bought": "1733300000", "type": "Lending"}]} {"timestamp": 1733884281.9774096, "result": [{"name": "Kamino USDC Lending", "description": "Kamino USDC Lending", "apy": 26.85, "url": "https://app.kamino.finance/lending/reserve/DxXdAyU3kCjnyggvHmY5nAwg5cRbbmdyX3npfDMjjMek/Ga4rZytCpq1unD4DbEJ5bkHeUz9g3oh9AAFEi6vSauXp", "value": 50.03, "updated": "1733877495", "initial": 50, "bought": "1733717057", "type": "Lending"}, {"name": "dYdX MegaVault", "description": "dYdX MegaVault", "apy": 55, "url": "https://dydx.trade/vault", "value": 44.58, "updated": "1733877495", "initial": 44, "bought": "1733300000", "type": "Lending"}]}