Skip to content

Commit

Permalink
feat(): add clearCache method
Browse files Browse the repository at this point in the history
  • Loading branch information
ihadeed committed Dec 30, 2016
1 parent dbb43af commit 6bcc799
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,15 @@ export class MyMainAppComponent {

// disable spinners by default, you can add [spinner]="true" to a specific component instance later on to override this
imageLoaderConfig.enableSpinner(false);

// set the maximum concurrent connections to 10
imageLoaderConfig.setConcurrency(10);
}

}
```

Below are all the methods that the provider has:
Below are all the methods that the config provider has:

#### enableDebugMode()
Enables debug mode to receive console logs, errors, warnings.
Expand Down Expand Up @@ -134,6 +137,21 @@ Set a custom directory name to store the cached images in.
#### setConcurrency(concurrency: number)
Set the maximum number of concurrent connections. Cached images will be loaded instantly, this limit is only for new images.

# Clearing the cache
```typescript

import { ImageLoader } from 'ionic-image-loader';

@Component(...)
class MyComponent {

constructor(imageLoader: ImageLoader) {
imageLoader.clearCache();
}

}

```

# Contributing
- **Having trouble?** Create an issue [here](https://github.com/zyramedia/ionic-image-loader/issues/new)
Expand Down
28 changes: 28 additions & 0 deletions src/providers/image-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,34 @@ export class ImageLoader {
}
}

/**
* Clears the cache
*/
clearCache(): void {

const clear = () => {

if (!this.isInit) {
// do not run this method until our service is initialized
setTimeout(clear.bind(this), 500);
return;
}

// pause any operations
this.isInit = false;

File.removeRecursively(cordova.file.cacheDirectory, this.config.cacheDirectoryName)
.then(() => {
this.initCache(true);
})
.catch(this.throwError.bind(this));

};

clear();

}

/**
* Downloads an image via cordova-plugin-file-transfer
* @param imageUrl {string} The remote URL of the image
Expand Down

0 comments on commit 6bcc799

Please sign in to comment.