Return an item from the threadlocal cache. The cache should be viewed as two nested dictionaries. The outer key is usually the id for the sequence where the cached item was generated. The inner key is the product type. Retrieving a cached item behaves like: value = cache
(key, product)
| 92 | |
| 93 | |
| 94 | def get_cached_item(key, product): |
| 95 | """Return an item from the threadlocal cache. |
| 96 | |
| 97 | The cache should be viewed as two nested dictionaries. The outer key is |
| 98 | usually the id for the sequence where the cached item was generated. The |
| 99 | inner key is the product type. |
| 100 | |
| 101 | Retrieving a cached item behaves like: |
| 102 | |
| 103 | value = cache[key][product] |
| 104 | |
| 105 | The cache is thread local, so stored items are only available in |
| 106 | the thread that cached them. |
| 107 | |
| 108 | Args: |
| 109 | |
| 110 | key (:obj:`int`): The outer dictionary cache key, which is typically |
| 111 | the id of the sequence where the cached item was generated. |
| 112 | |
| 113 | product (:obj:`str`): The inner dictionary cache key, which is a |
| 114 | string for the product type. |
| 115 | |
| 116 | Returns: |
| 117 | |
| 118 | :obj:`object`: The cached object. |
| 119 | |
| 120 | See Also: |
| 121 | |
| 122 | :meth:`cache_item` |
| 123 | |
| 124 | """ |
| 125 | global _local_storage |
| 126 | |
| 127 | _shrink_cache() |
| 128 | |
| 129 | if key is None or get_cache_size == 0: |
| 130 | return None |
| 131 | |
| 132 | cache = getattr(_local_storage, "cache", None) |
| 133 | |
| 134 | if cache is None: |
| 135 | return None |
| 136 | |
| 137 | if len(cache) == 0: |
| 138 | return None |
| 139 | |
| 140 | prod_dict = cache.get(key, None) |
| 141 | |
| 142 | if prod_dict is None: |
| 143 | return None |
| 144 | |
| 145 | result = prod_dict.get(product, None) |
| 146 | |
| 147 | return result |
| 148 | |
| 149 | |
| 150 | def _get_cache(): |