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

to.imagecache

v1.0.1

Published

A simple image cacher module for Titanium Applications if you want to maintain it manually

Downloads

2

Readme

To.ImageCache

A simple CommonJS module to cache images a little less temporarily, and configurable

Setup

Add To.ImageCache CommonJS module to your project. Either download this project, or install using gittio

Through http://gitt.io

gittio install To.ImageCache

Follow regular steps to include it in your project

Through NPM

In classic go to the Resources folder, for Alloy go to the lib directory of your project, then run the following command

npm install to.imagecache Note: if your app doesn't have node_modules yet, run npm init first!

Configuration

IMPORTANT: Version 1.0 is not backwards compatible with previous versions. Name has changed to lowercase for NPM support

The configuration is simple: No configuration is needed, unless you want to change something.

All current properties available shown below

require('to.imagecache').config({
	debug: true, //default "false"
	expireTime: 100000, // time in seconds, default 43200 = 12 hours
	folder: 'CustomFolder', // folder to store the cache in, default "ToCache"
	remoteBackup: true // iOS Only do you want the images to be backed up to iCloud?
});

The config can be changed at all times, between different files so support multiple folders, expiration times and file specfic backup properties. You only have to pass what you want to change from now on. No need to pass all config properties

If you want to make a copy of the config, so you can restore it later, use the getter

var config = require('to.imagecache').config();

All available images will be stored in Properties

 Ti.App.Properties.getList('To.ImageCache.ImageList');

There is, however, no need to call this list manually unless you really want to. Best to use build in functionality

Usage

There are 2 methods to use the module.

Only call the module when the image is needed, it will then, return a blob of the image while you wait.

Note: This might cause delays in your app and is only recommended for smaller images

var blob = require('to.imagecache').remoteImage('http://example.com/image.jpg');

This will cache the image the first time it is called, and the next time you request this same file it will return the same blob, but this time stored locally

Pre-cache images before they are needed

This method is preferred for bigger images, as this can happen in the background

require('to.imagecache').cache('http://example.com/image.jpg');

This function will NOT return a blob, but will cache the file using XHR.

Aditonally, you can add a timeout and callback function:

require('to.imagecache').cache('http://example.com/image.jpg', 25000, function(blob){
	$.imageView.image = blob;
});

Clearing Cache

You want, of course, to clear the cache when needed. This is NOT done automatically.

The best function to call is flushExpired

require('to.imagecache').flushExpired();

This function will remove all files older than the expired time.

You can also clear all cache

require('to.imagecache').clearCache();

This will remove all cached files regardless of expired time.

You can also remove a single file by URL:

require('to.imagecache').removeRemote('http://example.com/image.jpg');

This will also NOT take expiry time in consideration

If you know the filename (which is internally generated, so you probably won't), you can remove by filename too

require('to.imagecache').removeFile('a128a10e623e08c9b5b704bf162d770e');

Advanced

You can fetch the entire cache size, in bytes, from the module. This could, for example, be used to display users so they can be aware how much cache is present, and you could give the users the ability to remove cache manually

require('to.imagecache').cacheSize()

You can also, at a later point, update the config. Expire time is per-file, and stored per-file. So changing it later will not update the currently stored files. Might be usefull for different expiry times.

Also the folder can be changed multiple times. Folders are also stored per file, so changable all the time.