get method
获取缓存数据
Implementation
V? get(String key) {
switch (mode) {
case CacheMode.memory:
return _memoryCache?.get(key);
case CacheMode.persistent:
return _persistentCache?.get(key);
case CacheMode.hybrid:
// 先查内存
final memoryValue = _memoryCache?.get(key);
if (memoryValue != null) return memoryValue;
// 内存 miss,查磁盘
final diskValue = _persistentCache?.get(key);
if (diskValue != null) {
// 加载到内存
_memoryCache?.put(key, diskValue);
}
return diskValue;
}
}