Skip to content

Commit c1dfdf0

Browse files
docs: added testID prop and new getCustomCacheKey config option
1 parent f2237a6 commit c1dfdf0

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,24 @@ CacheManager.config = {
8181
};
8282
```
8383

84+
#### Custom cache key, useful for caching images from Amazon's S3 and similar services, add this (or whatever suits your needs) on `CacheManager.config`:
85+
86+
```tsx
87+
CacheManager.config = {
88+
// ...
89+
getCustomCacheKey: (source: string) => {
90+
// Remove params from the URL for chacing images (useful for caching images from Amazons S3 bucket and etc)
91+
let newCacheKey = source;
92+
if (source.includes('?')) {
93+
newCacheKey = source.substring(0, source.lastIndexOf('?'));
94+
}
95+
return newCacheKey;
96+
}
97+
}
98+
```
99+
100+
101+
84102
#### `cacheLimit` config: (auto pruning of cached files)
85103

86104
If `cacheLimit` is set to `0` (default value) then the cache will never be auto pruned. This setting accepts a number of Bytes eg. `1024 * 1024 * 256`(~256MB) and requires `react-native-file-access` >= 2.4.0, if you're using < 2.4.0 then leave the default value `0` (disabled).
@@ -176,7 +194,7 @@ await CacheManager.isImageCached(uri);
176194
#### `CachedImage` accepts the following props:
177195

178196
| Properties | PropType | Description |
179-
| -------------------------------- | -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
197+
|----------------------------------|----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
180198
| `source` | `String` | (**Required**) Uri of remote image. |
181199
| `sourceAnimationDuration` | `Number` | `source` image animation duration when loading, defaults to `1000`ms (overrides config) |
182200
| `thumbnailSource` | `String` | (**Required**) Uri of the thumbnail image |
@@ -191,6 +209,7 @@ await CacheManager.isImageCached(uri);
191209
| `onLoad` | `Func` | Invoked when load completes successfully |
192210
| `onLoadEnd` | `Func` | Invoked when load either succeeds or fails |
193211
| `resizeMode` | `String` | React native Image component [resizeMode](https://reactnative.dev/docs/image#resizemode) defaults to `contain` |
212+
| `testID` | `String` | testID, useful for tests |
194213
| `style` | `Object` | `source` AND `thumbnailSource` image style |
195214
| `options` | `Object` | custom options for the fetch image http request eg. `{headers:{}, body:{}}` |
196215
| `accessibilityHint` | `string` | accessibility hint for `source` (optional) |

0 commit comments

Comments
 (0)