Public class IntegerVersionSignature implements Key Passing in signatures to loads is simple: Urls - Although the best way to invalidate urls is to make sure the server changes the url and updates the client when the content at the url changes, you can also use ObjectKey to mix in arbitrary metadata (such as a version number) instead.Files - You can use ObjectKey to mix in the File’s date modified time.These three attributes reliably catch edits and updates allowing you to cache media store thumbs. MediaStoreSignature allows you to mix the date modified time, mime type, and orientation of a media store item into the cache key. Media store content - For media store content, you can use Glide’s MediaStoreSignature class as your signature.Signatures work well for media store content, as well as any content you can maintain some versioning metadata for. Since it’s often difficult or impossible to change identifiers, Glide also offers the signature() API to mix in additional data that you control into your cache key. In practice, the best way to invalidate a cache file is to change your identifier when the content changes (url, uri, file path etc) when possible. The problem would be simpler if you were only ever allowed to load or cache the original image, but since Glide also caches thumbnails and provides various transformations, each of which will result in a new File in the cache, tracking down and deleting every cached version of an image is difficult. Cache Invalidationīecause disk cache are hashed keys, there is no good way to simply delete all of the cached files on disk that correspond to a particular url or file path. If the available options aren’t sufficient for your needs, you can also write your own DiskCache implementation. If you’d just like to update the entry for an item in the cache, see the documentation on invalidation below. It’s vastly faster to load an image from cache than it is to retrieve, decode, and transform it to create a new thumbnail. In general you want to try to avoid skipping caches. For local data AUTOMATIC will store the transformed thumbnail only because retrieving the original data is cheap if you need to generate a second thumbnail size or type. AUTOMATIC will store only the unmodified data backing your load when you’re loading remote data (like from URLs) because downloading remote data is expensive compared to resizing data already on disk. The default strategy, AUTOMATIC, tries to use the optimal strategy for local and remote images. The available strategies allow you to prevent your load from using or writing to the disk cache or choose to cache only the unmodified original data backing your load, only the transformed thumbnail produced by your load, or both. Disk Cache StrategiesĭiskCacheStrategy can be applied with the diskCacheStrategy method to an individual request. Glide provides a number of options that allow you to choose how loads will interact with Glide’s caches on a per request basis. To generate the name of disk cache keys on disk, the individual elements of the keys are hashed to create a single String key, which is then used as the file name in the disk cache. The keys used for active resources and the memory cache also differ slightly from those used from the resource disk cache to accomodate in memory Options like those thataffect the configuration of the Bitmap or other decode time only parameters. The requested data type (Bitmap, GIF, etc).In fact, the cache keys for steps 1-3 (Active resources, memory cache, resource disk cache) also include a number of other pieces of data including: If you are using a custom model, it needs to correctly implements hashCode() and equals() The model the load is requested for (File, Uri, Url).In Glide 4, all cache keys contain at least two elements: If all four steps fail to find the image, then Glide will go back to the original source to retrieve the data (the original File, Uri, Url etc).įor details on default sizes and locations of Glide’s caches or to configure those parameters, see the configuration page. The second two steps check to see if the image is on disk and return quickly, but asynchronously. The first two steps check to see if the resource is in memory and if so, return the image immediately. Data - Was the data this image was obtained from written to the disk cache before?.Resource - Has this image been decoded, transformed, and written to the disk cache before?.Memory cache - Was this image recently loaded and still in memory?.Active resources - Is this image displayed in another View right now?. By default, Glide checks multiple layers of caches before starting a new request for an image:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |