1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
30 """fifo, is the actual cache containing a limited set of copies of row data
31 so the data in fifo, is always immediately accessible to the gui thread,
32 with zero delay as you scroll down the table view, fifo is filled and
33 refilled with data queried from the database
34
35 the cache can be queried either by the row number or by the primary key
36 of the object represented by the row data.
37 """
39 self.max_entries = max_entries
40 self.entities = []
41 self.data_by_rows = dict()
42 self.rows_by_entity = dict()
43
45 self.delete_by_entity(entity)
46 self.data_by_rows[row] = (entity, value)
47 self.rows_by_entity[entity] = row
48 self.entities.append(entity)
49 if len(self.entities)>self.max_entries:
50 entity = self.entities.pop(0)
51 row = self.rows_by_entity[entity]
52 del self.data_by_rows[row]
53 del self.rows_by_entity[entity]
54
56 (entity, value) = self.data_by_rows[row]
57 del self.data_by_rows[row]
58 del self.rows_by_entity[entity]
59 return row
60
62 """Remove everything in the cache related to an entity instance
63 returns the row at which the data was stored if the data was in the
64 cache, return None otherwise"""
65 row = None
66 try:
67 row = self.rows_by_entity[entity]
68 del self.data_by_rows[row]
69 del self.rows_by_entity[entity]
70 except KeyError:
71 pass
72 try:
73 self.entities.remove(entity)
74 except ValueError:
75 pass
76 return row
77
79 return self.data_by_rows[row][1]
80
82 return self.rows_by_entity[entity]
83
85 return self.data_by_rows[row][0]
86