self._conn = sqlite3.connect(db_file, check_same_thread=False)
def is_registered(self, name):
- if not db_file: return False
+ if not self._conn: return False
c = self._conn.cursor()
c.execute("SELECT COUNT(*) FROM cache WHERE name=?", (name,))
- return c.fetchone() != None
+ return c.fetchone()[0] == 1
def clean(self):
- if not db_file: return
+ if not self._conn: return
c = self._conn.cursor()
c.execute("DELETE FROM cache WHERE access_time<?", (int(time.time()) - 604800,))
self._conn.commit()
def register(self, name):
- if not db_file: return
+ if not self._conn: return
c = self._conn.cursor()
c.execute( '''INSERT INTO cache (name, access_time) VALUES (?, ?)''',
(name, int(time.time())) )
self._conn.commit()
def refresh(self, name):
- if not db_file: return
+ if not self._conn: return
c = self._conn.cursor()
c.execute( "UPDATE cache SET access_time=? WHERE name=?",
(int(time.time()), name) )