| 55 | localQueryCache = typeQueryCache[function] = {} |
| 56 | |
| 57 | def setCache(cacheKey, args, kwargs): |
| 58 | items = function(*args, **kwargs) |
| 59 | IDs = set() |
| 60 | localQueryCache[cacheKey] = (isinstance(items, list), IDs) |
| 61 | stuff = items if isinstance(items, list) else (items,) |
| 62 | for item in stuff: |
| 63 | ID = getattr(item, "ID", None) |
| 64 | if ID is None: |
| 65 | # Some uncachable data, don't cache this query |
| 66 | del localQueryCache[cacheKey] |
| 67 | break |
| 68 | localItemCache[ID] = item |
| 69 | IDs.add(ID) |
| 70 | |
| 71 | return items |
| 72 | |
| 73 | def checkAndReturn(*args, **kwargs): |
| 74 | useCache = kwargs.pop("useCache", True) |