Return all keys currently in the cache. Uses the roster file for O(occupied) lookup, reading only the key field from the index (no heap access).
(self)
| 1477 | return self.get(key, default=None) is not None |
| 1478 | |
| 1479 | def list_keys(self): |
| 1480 | """ |
| 1481 | Return all keys currently in the cache. |
| 1482 | |
| 1483 | Uses the roster file for O(occupied) lookup, reading only the key |
| 1484 | field from the index (no heap access). |
| 1485 | """ |
| 1486 | with self._thread_lock: |
| 1487 | if not self.open(write=False): |
| 1488 | return [] |
| 1489 | slots = self._roster_read() |
| 1490 | if not slots: |
| 1491 | return [] |
| 1492 | |
| 1493 | ret = [] |
| 1494 | for slot in slots: |
| 1495 | if slot == 0 or slot >= self.size: |
| 1496 | continue |
| 1497 | offset = slot * self.slot_size |
| 1498 | if self._mm[offset] != OCCUPIED: |
| 1499 | continue |
| 1500 | raw = self._mm[ |
| 1501 | offset + self._key_off : offset + self._key_off + self.key_size |
| 1502 | ] |
| 1503 | null_pos = raw.find(b"\x00") |
| 1504 | key_bytes = raw[:null_pos] if null_pos != -1 else raw |
| 1505 | if not key_bytes: |
| 1506 | continue |
| 1507 | try: |
| 1508 | ret.append(key_bytes.decode("utf-8")) |
| 1509 | except UnicodeDecodeError: |
| 1510 | ret.append(salt.utils.stringutils.to_unicode(key_bytes)) |
| 1511 | |
| 1512 | return ret |
| 1513 | |
| 1514 | def list_items(self): |
| 1515 | """ |