Skip to content

Commit 74f0aa7

Browse files
committed
Cache directory and optional NO_CACHE
1 parent b5d7b1a commit 74f0aa7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

async_substrate_interface/utils/cache.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import functools
2+
import os
23
import pickle
34
import sqlite3
45
import asyncstdlib as a
56

7+
CACHE_LOCATION = os.path.expanduser("~/.cache/async-substrate_interface") if os.getenv("NO_CACHE") != "1" else ":memory:"
8+
69

710
def _get_table_name(func):
811
"""Convert "ClassName.method_name" to "ClassName_method_name"""
@@ -43,7 +46,7 @@ def _insert_into_cache(c, conn, table_name, key, result, chain):
4346

4447

4548
def sql_lru_cache(func, max_size=None):
46-
conn = sqlite3.connect("/tmp/cache.db")
49+
conn = sqlite3.connect(CACHE_LOCATION)
4750

4851
table_name = _get_table_name(func)
4952
_create_table(conn, table_name)
@@ -68,7 +71,7 @@ def inner(self, *args, **kwargs):
6871

6972

7073
def async_sql_lru_cache(func, max_size=None):
71-
conn = sqlite3.connect("/tmp/cache.db")
74+
conn = sqlite3.connect(CACHE_LOCATION)
7275
table_name = _get_table_name(func)
7376
_create_table(conn, table_name)
7477

0 commit comments

Comments
 (0)