Используя пример, представленный на сайте nativescript.org
Я создал страницу для тестирования компонента кэша изображений.
ТНС-ядро-модули / щ / изображений кэш
cache.push () работает нормально.
Каждый раз, когда я использую cache.get (url), объект возвращает ноль. Я никогда не могу получить кэшированные изображения.
При завершении нажатия кажется, что изображение можно извлечь из кэша, но, похоже, оно не сохраняется.
Это происходит как на эмуляторе, так и на реальном подключенном устройстве Android.
Я попытался создать пустое приложение javascript для hellow-world с нуля.
tns create --template tns-template-hello-world для тестирования образца и имеет ту же проблему.
const cache = new Cache();
cache.placeholder = fromFile("~/images/logo.png");
cache.maxRequests = 5;
// set the placeholder while the desired image is donwloaded
viewModel.set("imageSource", cache.placeholder);
// Enable download while not scrolling
cache.enableDownload();
let cachedImageSource;
const url = "https://avatars1.githubusercontent.com/u/7392261?v=4";
// Try to read the image from the cache
const image = cache.get(url);
if (image) {
// If present -- use it.
cachedImageSource = imageSource.fromNativeSource(image);
viewModel.set("imageSource", cachedImageSource);
} else {
// If not present -- request its download + put it in the cache.
cache.push({
key: url,
url: url,
completed: (image, key) => {
if (url === key) {
cachedImageSource = fromNativeSource(image);
viewModel.set("imageSource", cachedImageSource); // set the downloaded iamge
}
}
});
}
// Disable download while scrolling
cache.disableDownload();