MCPcopy Create free account
hub / github.com/cisco/mindmeld / put

Method put

mindmeld/query_cache.py:167–200  ·  view source on GitHub ↗

Adds a ProcessedQuery to the cache Args: key(str): A key generated by QueryCache.get_key() for this example processed_query(ProcessedQuery): The ProcessedQuery generated for this example Returns: integer: The unique id of the query in the

(self, key, processed_query)

Source from the content-addressed store, hash-verified

165 return row[0] if row else None
166
167 def put(self, key, processed_query):
168 """
169 Adds a ProcessedQuery to the cache
170
171 Args:
172 key(str): A key generated by QueryCache.get_key() for this example
173 processed_query(ProcessedQuery): The ProcessedQuery generated for this example
174 Returns:
175 integer: The unique id of the query in the cache.
176 """
177 data = json.dumps(processed_query.to_cache())
178
179 def commit_to_db(connection):
180 cursor = connection.cursor()
181 cursor.execute("""
182 INSERT OR IGNORE into queries values (?, ?, ?, ?, ?);
183 """, (key,
184 data,
185 processed_query.query.text,
186 processed_query.domain,
187 processed_query.intent,
188 ))
189 connection.commit()
190
191 if self.memory_connection:
192 commit_to_db(self.memory_connection)
193 rowid = self.key_to_row_id(key)
194 self.batch_writes.append(str(rowid))
195 if len(self.batch_writes) == self.batch_write_size:
196 self.flush_to_disk()
197 else:
198 commit_to_db(self.disk_connection)
199
200 return self.key_to_row_id(key)
201
202 @lru_cache(maxsize=1)
203 def get(self, row_id):

Callers 4

test_disk_query_cacheFunction · 0.95
test_memory_query_cacheFunction · 0.95
cache_query_fileFunction · 0.80

Calls 4

key_to_row_idMethod · 0.95
flush_to_diskMethod · 0.95
to_cacheMethod · 0.45
appendMethod · 0.45

Tested by 2

test_disk_query_cacheFunction · 0.76
test_memory_query_cacheFunction · 0.76