Try to get a hit in the cache, return None otherwise
(self, crc)
| 60 | self._rw_cache = rw_cache |
| 61 | |
| 62 | def fetch(self, crc): |
| 63 | """ Try to get a hit in the cache, return None otherwise """ |
| 64 | cache_data = None |
| 65 | pattern = '%08X.json' % crc |
| 66 | hit = None |
| 67 | |
| 68 | for name in self._cache_files: |
| 69 | if (name.endswith(pattern)): |
| 70 | hit = name |
| 71 | |
| 72 | if (hit): |
| 73 | try: |
| 74 | cache = open(hit) |
| 75 | cache_data = json.load(cache, |
| 76 | object_hook=self._decoder) |
| 77 | cache.close() |
| 78 | except Exception as exp: |
| 79 | logger.warning('Error while parsing cache file [%s]:%s', |
| 80 | hit, str(exp)) |
| 81 | |
| 82 | return cache_data |
| 83 | |
| 84 | def insert(self, crc, toc): |
| 85 | """ Save a new cache to file """ |