diff --git a/src/lib/media/image-sizes.ts b/src/lib/media/image-sizes.ts index b7787ec171..017300b41e 100644 --- a/src/lib/media/image-sizes.ts +++ b/src/lib/media/image-sizes.ts @@ -2,7 +2,23 @@ import {Image} from 'react-native' import type {Dimensions} from '#/lib/media/types' -const sizes: Map = new Map() +type CacheStorageItem = {key: string; value: T} +const createCache = (cacheSize: number) => ({ + _storage: [] as CacheStorageItem[], + get(key: string) { + const {value} = + this._storage.find(({key: storageKey}) => storageKey === key) || {} + return value + }, + set(key: string, value: T) { + if (this._storage.length >= cacheSize) { + this._storage.shift() + } + this._storage.push({key, value}) + }, +}) + +const sizes = createCache(50) const activeRequests: Map> = new Map() export function get(uri: string): Dimensions | undefined {