getCache<T> static method
MultiLevelCache<T>
getCache<T>(
- String name, {
- CacheStrategy? strategy,
- StorageBackend? diskStorage,
Get or create cache
Implementation
static MultiLevelCache<T> getCache<T>(
String name, {
CacheStrategy? strategy,
StorageBackend? diskStorage,
}) {
final existing = _caches[name];
if (existing != null) {
// Check if the existing cache is the same type
try {
return existing as MultiLevelCache<T>;
} catch (e) {
// Type mismatch - remove old cache and create new one
_caches.remove(name);
}
}
final cache = MultiLevelCache<T>(
strategy: strategy,
diskStorage: diskStorage,
);
_caches[name] = cache;
return cache;
}