fn find_or_decode_postchecked(
        &self,
        key: &str,
    ) -> Result<Arc<DecoderImpl::Output>, AssetCacheError<DecoderImpl::Error>> {
        // First, if we can find the item, return it immediately.
        if let Some(x) = self.search_for_item(key) {
            return Ok(x);
        }

        // If we can get the size of the item, and it is less than the single object limit, we cache a vec of bytes.
        // Otherwise, we feed the reader into the decoder directly.

        let mut bytes_reader = self.vfs.open(key).map_err(AssetCacheError::Vfs)?;
        let size = bytes_reader.get_size().map_err(AssetCacheError::Vfs)?;
        let decoded = if size <= self.config.max_single_object_bytes_cost {
            let maybe_cached_bytes = self.bytes_cache.lock().unwrap().get(key);
            if let Some(x) = maybe_cached_bytes {
                self.decoder
                    .decode_bytes(&x[..])
                    .map_err(AssetCacheError::Decoder)?
            } else {
                // Read to a vec, insert that vec, then read from the vec.
                let mut dest = vec![];
                bytes_reader
                    .read_to_end(&mut dest)
                    .map_err(AssetCacheError::Vfs)?;
                let will_use = {
                    let mut guard = self.bytes_cache.lock().unwrap();
                    guard.insert(key.to_string().into(), dest, size);
                    guard.get(key).expect("We just inserted this")
                };
                self.decoder
                    .decode_bytes(&will_use[..])
                    .map_err(AssetCacheError::Decoder)?
            }
        } else {
            // The object was too big, or we couldn't get the size; in this case, we feed the vfs directly to the
            // decoder.
            self.decoder
                .decode(bytes_reader)
                .map_err(AssetCacheError::Decoder)?
        };

        let cost = self
            .decoder
            .estimate_cost(&decoded)
            .map_err(AssetCacheError::Decoder)?;
        let res = if cost <= self.config.max_single_object_decoded_cost {
            let mut guard = self.decoded_cache.lock().unwrap();
            guard.insert(key.to_string().into(), decoded, cost);
            guard.get(key).expect("Just inserted")
        } else {
            Arc::new(decoded)
        };

        let weak = Arc::downgrade(&res);
        self.weak_refs
            .write()
            .unwrap()
            .insert(key.to_string(), weak);
        Ok(res)
    }
/// Decode an item for the cache, assuming we definitely know it isn't present and are holding the guard necessary
/// to stop other threads from attempting to do so in parallel.
///
/// This is hard to break up into smaller functions, unfortunately.
Decode an item for the cache, assuming we definitely know it isn't present and are holding the guard necessary
to stop other threads from attempting to do so in parallel.

This is hard to break up into smaller functions, unfortunately.
Decode an item for the cache assuming we definitely know it isn ' t present and are holding the guard necessary to stop other threads from attempting to do so in parallel . This is hard to break up into smaller functions unfortunately .
fn find_or_decode_postchecked(
        &self,
        key: &str,
    ) -> Result<Arc<DecoderImpl::Output>, AssetCacheError<DecoderImpl::Error>> {
        // First, if we can find the item, return it immediately.
        if let Some(x) = self.search_for_item(key) {
            return Ok(x);
        }
        // If we can get the size of the item, and it is less than the single object limit, we cache a vec of bytes.
        // Otherwise, we feed the reader into the decoder directly.
        let mut bytes_reader = self.vfs.open(key).map_err(AssetCacheError::Vfs)?;
        let size = bytes_reader.get_size().map_err(AssetCacheError::Vfs)?;
        let decoded = if size <= self.config.max_single_object_bytes_cost {
            let maybe_cached_bytes = self.bytes_cache.lock().unwrap().get(key);
            if let Some(x) = maybe_cached_bytes {
                self.decoder
                    .decode_bytes(&x[..])
                    .map_err(AssetCacheError::Decoder)?
            } else {
                // Read to a vec, insert that vec, then read from the vec.
                let mut dest = vec![];
                bytes_reader
                    .read_to_end(&mut dest)
                    .map_err(AssetCacheError::Vfs)?;
                let will_use = {
                    let mut guard = self.bytes_cache.lock().unwrap();
                    guard.insert(key.to_string().into(), dest, size);
                    guard.get(key).expect("We just inserted this")
                };
                self.decoder
                    .decode_bytes(&will_use[..])
                    .map_err(AssetCacheError::Decoder)?
            }
        } else {
            // The object was too big, or we couldn't get the size; in this case, we feed the vfs directly to the
            // decoder.
            self.decoder
                .decode(bytes_reader)
                .map_err(AssetCacheError::Decoder)?
        };
        let cost = self
            .decoder
            .estimate_cost(&decoded)
            .map_err(AssetCacheError::Decoder)?;
        let res = if cost <= self.config.max_single_object_decoded_cost {
            let mut guard = self.decoded_cache.lock().unwrap();
            guard.insert(key.to_string().into(), decoded, cost);
            guard.get(key).expect("Just inserted")
        } else {
            Arc::new(decoded)
        };
        let weak = Arc::downgrade(&res);
        self.weak_refs
            .write()
            .unwrap()
            .insert(key.to_string(), weak);
        Ok(res)
    }
fn find_or_decode_postchecked ( & self , key : & str , ) -> Result < Arc < DecoderImpl :: Output > , AssetCacheError < DecoderImpl :: Error > > { // First, if we can find the item, return it immediately. if let Some ( x ) = self . search_for_item ( key ) { return Ok ( x ) ; } // If we can get the size of the item, and it is less than the single object limit, we cache a vec of bytes. // Otherwise, we feed the reader into the decoder directly. let mut bytes_reader = self . vfs . open ( key ) . map_err ( AssetCacheError :: Vfs ) ? ; let size = bytes_reader . get_size ( ) . map_err ( AssetCacheError :: Vfs ) ? ; let decoded = if size <= self . config . max_single_object_bytes_cost { let maybe_cached_bytes = self . bytes_cache . lock ( ) . unwrap ( ) . get ( key ) ; if let Some ( x ) = maybe_cached_bytes { self . decoder . decode_bytes ( & x [ .. ] ) . map_err ( AssetCacheError :: Decoder ) ? } else { // Read to a vec, insert that vec, then read from the vec. let mut dest = vec ! [ ] ; bytes_reader . read_to_end ( & mut dest ) . map_err ( AssetCacheError :: Vfs ) ? ; let will_use = { let mut guard = self . bytes_cache . lock ( ) . unwrap ( ) ; guard . insert ( key . to_string ( ) . into ( ) , dest , size ) ; guard . get ( key ) . expect ( " " ) } ; self . decoder . decode_bytes ( & will_use [ .. ] ) . map_err ( AssetCacheError :: Decoder ) ? } } else { // The object was too big, or we couldn't get the size; in this case, we feed the vfs directly to the // decoder. self . decoder . decode ( bytes_reader ) . map_err ( AssetCacheError :: Decoder ) ? } ; let cost = self . decoder . estimate_cost ( & decoded ) . map_err ( AssetCacheError :: Decoder ) ? ; let res = if cost <= self . config . max_single_object_decoded_cost { let mut guard = self . decoded_cache . lock ( ) . unwrap ( ) ; guard . insert ( key . to_string ( ) . into ( ) , decoded , cost ) ; guard . get ( key ) . expect ( " " ) } else { Arc :: new ( decoded ) } ; let weak = Arc :: downgrade ( & res ) ; self . weak_refs . write ( ) . unwrap ( ) . insert ( key . to_string ( ) , weak ) ; Ok ( res ) }
Decode an item for the cache, assuming we definitely know it isn't present and are holding the guard necessary
to stop other threads from attempting to do so in parallel.
Decode an item for the cache assuming we definitely know it isn ' t present and are holding the guard necessary to stop other threads from attempting to do so in parallel .
&self
key
&str
&self
key
&str