npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ionic-img-cache

v1.3.2

Published

Image caching for Ionic 1.x applications.

Downloads

22

Readme

ionic-img-cache 🖼

Bower version npm version npm

Ionic directive to cache images or element background images on first load. Working on top of imgcache.js library.

This library works with Ionic Framework (v >= 1.0), the supported platforms being:

  • Android
  • iOS
  • Windows Phone 8.1
  • Amazon Fire OS

Instalation

  • Install

    • npm npm install --save ionic-img-cache

    • yarn yarn add ionic-img-cache

    • Bower bower install --save ionic-img-cache

  • Add imgcache.js and ionic-img-cache.min.js files to your app index.html file.

  • Install required cordova plugins:

      cordova plugin add cordova-plugin-device
      cordova plugin add cordova-plugin-file
      cordova plugin add cordova-plugin-file-transfer
  • Inject as dependency into your app, example:

  angular.module('app', [
      'ionic',
      'ionicImgCache'
    ])
  • Edit config.xml file:
    • Add <access origin="*"/>
    • For Android add:
      <access origin="cdvfile://*"/>
      <allow-intent href="cdvfile://*"/>
      <preference name="AndroidPersistentFileLocation" value="Compatibility" />
    • For iOS add <preference name="iosPersistentFileLocation" value="Library"/>

Required cordova plugins:

Usage

Just add ion-img-cache attribute to img tag you want to cache.

Example: Image: <img ion-img-cache ng-src="{{ imagePath }}"/>

Background image: <div ion-img-cache-bg>Element with background image set with css or ng-style</div>

Component: Note: Components are supported with angular >=1.5.0, if older version used without component polyfill, component can't be used. <ion-img-cache-component img-src="{{ imagePath }}" alt="my fancy picture"></<on-img-cache-component>

Cache service public methods:

All methods are async, wrapped into angular $q service.

add

Adds file to local cache.

Example:

angular.module('app')
  .controller('Ctrl', function(ionImgCacheSrv) {
    ionImgCacheSrv.add('path/to/my/asset.jpg')
      .then(function(path) {
        console.log('File cached in ' + path);
      })
      .catch(function(err) {
        console.error(err);
      })
  });

get

Gets file local url if it present in cache.

Example:

angular.module('app')
  .controller('Ctrl', function(ionImgCacheSrv) {
    ionImgCacheSrv.get('path/to/my/asset.jpg')
      .then(function(path) {
        console.log('File found in cache ' + path);
      })
      .catch(function(err) {
        console.error(err);
      })
  });

remove

Removes file from local cache if it present.

Example:

angular.module('app')
  .controller('Ctrl', function(ionImgCacheSrv) {
    ionImgCacheSrv.remove('path/to/my/asset.jpg')
      .then(function() {
        console.log('File removed from cache');
      })
      .catch(function(err) {
        console.error(err);
      })
  });

checkCacheStatus

Checks file cache status by url.

Example:

angular.module('app')
  .controller('Ctrl', function(ionImgCacheSrv) {
    ionImgCacheSrv.checkCacheStatus('path/to/my/asset.jpg')
      .then(function(path) {
        console.log('File added/found in/to cache' + path);
      })
      .catch(function(err) {
        console.error(err);
      })
  });

checkBgCacheStatus

Checks elements background file cache status by element.

Example:

angular.module('app')
  .controller('Ctrl', function(ionImgCacheSrv) {
    ionImgCacheSrv.checkBgCacheStatus(angular.element('#my-element'))
      .then(function(path) {
        console.log('File added/found in/to cache' + path);
      })
      .catch(function(err) {
        console.error(err);
      })
  });

clearCache

Clears all cahced files.

Example:

angular.module('app')
  .controller('Ctrl', function(ionImgCacheSrv) {
    ionImgCacheSrv.clearCache()
      .then(function(path) {
        console.log('Cache successuly cleared');
      })
      .catch(function(err) {
        console.error(err);
      })
  });

getCacheSize

Gets local cache size in bytes.

Example:

angular.module('app')
  .controller('Ctrl', function(ionImgCacheSrv) {
    ionImgCacheSrv.getCacheSize()
      .then(function(result) {
        console.log('Cache size is ' + result + ' bytes');
      })
      .catch(function(err) {
        console.error(err);
      })
  });

Options

Caching can be configured via ionicImgCacheProvider, there are available parameters in this provider:

debug

Type: Boolean

Default value: false

Enables ImgCache debug mode.

quota

Type: Number

Default value: 50

Quota for storage size available for cached images in MB.

headers

Type: Object

Default value: {}

Adds custom request headers.

folder

Type: String

Default value: ion-img-cache

Set name of cached files directory.

cacheClearSize

Type: Number

Default value: 0

Set quota after which cache folder will be cleared.

Example:

angular.module('app')
  .config(function(ionicImgCacheProvider) {
    // Enable imgCache debugging.
    ionicImgCacheProvider.debug(true);

    // Set storage size quota to 100 MB.
    ionicImgCacheProvider.quota(100);

    // Set folder for cached files.
    ionicImgCacheProvider.folder('my-cache');

    // Set cache clear limit.
    ionicImgCacheProvider.cacheClearSize(100);
  });