DylanVann / react-native-fast-image

🚩 FastImage, performant React Native image component.
MIT License
8.09k stars 1.47k forks source link

will preload function check cache before hit image url? #955

Open naveenprakash74 opened 1 year ago

naveenprakash74 commented 1 year ago

my code Example:

const OptimizedImage = ({ imageUrl, ...restProps }) => {

  useEffect(() => {
    (async () => {
      await FastImage.preload([
        {
          uri: imageUrl
        },
      ]);
    })();
  }, []);

  return (
        <FastImage
          source={{ uri: optimizedImageUrl, priority: FastImage.priority.high }}
          {...restProps}
        />)

and My question is Supposed User open app first time preload function will run on componentmout and render image will run. What happened if user kill this app and reopen it will Preload function check the in cache the url already exist or it will fetch new image and overwrite previous cache?

ilovinht commented 1 year ago

I have the same question. When preload twice (just for example), will it write cache twice or check if the cache already exist?

itsashis4u commented 1 year ago

My assumption is it would. Since preload internally uses Glide.load()

When you call Glide.load() method to load an image, Glide first checks the in-memory cache, which is a small cache that stores recently used images. If the image is found in the in-memory cache, then it is returned immediately. If not, Glide checks the disk cache, which is a larger cache that stores previously loaded images. If the image is found in the disk cache, then it is decoded and returned. If not, Glide downloads the image and stores it in both the in-memory and disk caches for future use.