9 def __init__(self, db_file):
10 if not db_file: return
11 if not os.path.isfile(db_file):
12 self._conn = sqlite3.connect(db_file, check_same_thread=False)
15 self._conn = sqlite3.connect(db_file, check_same_thread=False)
17 def is_registered(self, name):
18 if not self._conn: return False
19 c = self._conn.cursor()
20 c.execute("SELECT COUNT(*) FROM cache WHERE name=?", (name,))
21 return c.fetchone() != None
24 if not self._conn: return
25 c = self._conn.cursor()
26 c.execute("DELETE FROM cache WHERE access_time<?", (int(time.time()) - 604800,))
30 def register(self, name):
31 if not self._conn: return
32 c = self._conn.cursor()
33 c.execute( '''INSERT INTO cache (name, access_time) VALUES (?, ?)''',
34 (name, int(time.time())) )
37 def refresh(self, name):
38 if not self._conn: return
39 c = self._conn.cursor()
40 c.execute( "UPDATE cache SET access_time=? WHERE name=?",
41 (int(time.time()), name) )
45 c = self._conn.cursor()
46 c.execute('''CREATE TABLE cache (name TEXT PRIMARY KEY, access_time INTEGER)''')