nativescript-image-cache
Version:
Nativescript image caching plugin using Fresco for Android and SDWebImageCache for iOS
104 lines (70 loc) • 2.35 kB
Markdown
[](https://badge.fury.io/js/nativescript-image-cache)
Nativescript image caching plugin using Fresco for Android and SDWebImageCache for iOS
```
tns plugin add nativescript-image-cache
```
Support NativeScript ~3.0.0 with Angular
| Property Name | Value | Platform |
|:----------------------|:----------------------------------|:----------|
| `stretch` | aspectFill, aspectFit, fill, none |ios,android|
| `src` | string |ios,android|
| `placeholder` | string |ios,android|
| `placeholderStretch` | aspectFill, aspectFit, fill, none |android |
| `radius` | number |android |
| `rounded` | boolean |android |
Initialization
```ts
import { initializeOnAngular } from 'nativescript-image-cache';
export class AppComponent {
constructor () {
initializeOnAngular();
}
}
```
Example usage:
```html
<NSImage
</NSImage>
```
Initialization (android only)
```js
const imageCache = require('nativescript-image-cache');
if (application.android) {
application.on('launch', () => {
imageCache.initialize();
});
}
```
Example usage:
```xml
<Page xmlns:IC="nativescript-image-cache">
<GridLayout rows='*' columns='*'>
<IC:NSImage stretch="fill" row="0"
col="0" placeholder="res://placeholder"
src="res://logo">
</IC:NSImage>
</GridLayout>
</Page>
```
Default cache purge time can be specified in number of days.
```ts
import { setCacheLimit } from 'nativescript-image-cache';
const cacheLimitInDays : number = 7;
setCacheLimit(cacheLimitInDays);
```
Default cache time for SDWebImageCache is 7 days, and for Fresco is 60 days.
```ts
import { clearCache } from 'nativescript-image-cache';
clearCache();
```
**(Android Only), you need to initialize in the application onlaunch event before clearing the cache**
The starting point for this plugin was [this great plugin](https://github.com/VideoSpike/nativescript-web-image-cache).