All Projects → nyancodeid → image-cache

nyancodeid / image-cache

Licence: MIT license
NodeJS Image cache with Base64 format

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to image-cache

prophetjs
Vanilla JS library to display toast messages.
Stars: ✭ 31 (+72.22%)
Mutual labels:  callback
vkbottle
Сustomizable asynchronous VK API framework
Stars: ✭ 371 (+1961.11%)
Mutual labels:  callback
GPSService
Demonstrates how to use a service to regularly update a activity with data via callback. Also allows the activity to call functions on the service.
Stars: ✭ 16 (-11.11%)
Mutual labels:  callback
angular-PubSub
Angular 1.x implementation of the Publish–Subscribe pattern.
Stars: ✭ 32 (+77.78%)
Mutual labels:  callback
DiffEqCallbacks.jl
A library of useful callbacks for hybrid scientific machine learning (SciML) with augmented differential equation solvers
Stars: ✭ 43 (+138.89%)
Mutual labels:  callback
Android-Code-Demos
📦 Android learning code demos.
Stars: ✭ 41 (+127.78%)
Mutual labels:  callback
ruling
Stateless rule engine
Stars: ✭ 19 (+5.56%)
Mutual labels:  callback
markright
A customizable markdown parser in Elixir: pure pattern matching.
Stars: ✭ 14 (-22.22%)
Mutual labels:  callback
mongoose-aggregate-paginate-v2
A cursor based custom aggregate pagination library for Mongoose with customizable labels.
Stars: ✭ 103 (+472.22%)
Mutual labels:  callback
EncoderTool
The EncoderTool is a library to manage and read out rotary encoders connected either directly or via multiplexers to ARM based boards. Encoder push buttons are supported. Callback functions can be attached to encoder changes and button presses to allow for event driven applications
Stars: ✭ 29 (+61.11%)
Mutual labels:  callback
TJImageCache
A fast, easy to use Objective-C image cache
Stars: ✭ 25 (+38.89%)
Mutual labels:  image-cache
space-router
Framework agnostic router for single page apps
Stars: ✭ 36 (+100%)
Mutual labels:  callback
do
Simplest way to manage asynchronicity
Stars: ✭ 33 (+83.33%)
Mutual labels:  callback
vk-callback-bot
Бот для сообществ VK на основе CallBack. Взаимодействие с клавиатурой, загрузка файлов.
Stars: ✭ 21 (+16.67%)
Mutual labels:  callback
lightflow
A tiny Promise-inspired control flow library for browser and Node.js.
Stars: ✭ 29 (+61.11%)
Mutual labels:  callback
react-shortcut
Convenient React component that detects if the given key combination is pressed, and triggers a callback
Stars: ✭ 16 (-11.11%)
Mutual labels:  callback
common
Metarhia Common Library
Stars: ✭ 55 (+205.56%)
Mutual labels:  callback
ProtoPromise
Robust and efficient library for management of asynchronous operations in C#/.Net.
Stars: ✭ 20 (+11.11%)
Mutual labels:  callback
Android-Alarm
This repository is an Alarm application, demonstrate how to use multiple pending intent to set alarm's time wake up. use popup menu, RecyclerView Adapter, use SQLite to store data
Stars: ✭ 25 (+38.89%)
Mutual labels:  callback
AjaxHandler
ASimple PHP Class to help handling Ajax Requests easily
Stars: ✭ 30 (+66.67%)
Mutual labels:  callback

image-cache

Build Status npm version

Powerful image cache for NodeJS

What is image-cache?

image-cache is nodejs module for cache image and serve with base64 format. image-cache using Asynchronous calls for best Performance.

New

  • Compressed options default is false
  • Library Core now using Javascript Classes
  • New syntax and function
  • Now image-cache using google proxy cache for best caching.

Installation

to install image-cache on your project, you can use NPM and Yarn with the following command,

NPM

npm install --save image-cache 

Yarn

yarn add image-cache

Usage

Start using image-cache

const imageCache = require('image-cache');

API

setOptions

is a function to replace options from default options. this function not returning something. for using this function, add this code after defining all variable.

imageCache.setOptions({
   compressed: false

   // write your custom options here
});

API

Key Data Type Default Value Description
dir string path.join(__dirname, 'cache/') directory root for cached files
compressed boolean false compressing cache output with zlib compressing maybe can make your processing cache little bit longer. for example without compressing is 6-7ms when using compressing is 150-185ms, but your cache file is a litle bit smaller than without compressing
extname string .cache file extension for your cache files
googleCache boolean true using google cache proxy

isCached()

Check is your image already cached or not. this function need 2 params.

imageCache.isCached(url, callback);

Params

Key Data Type
url string
callback function

Example Using Callback

imageCache.isCached(url, (exist) => {
   if (exist) {
      // do something with cached image
   }
});

Example Using Promise

imageCache.isCached(url).then((exist) => {
   if (exist) {
      // do something with cached image
   }
});

isCachedSync()

Check is your image is cached with Synchronous processing. return as boolean

Example

var exists = imageCache.isCachedSync(url);

API

Params Data Type Description
url string url of your image

getCache

Deprecated

get()

Get cached image

Example

imageCache.get(url, (error, image) => {
   console.log(image);

   // do something with image
});

API Callback

Key Data Type Description
image object cache data object
image.error boolean cache data error indicator
image.url string image source url before transform to base64 format
image.hashFile string filename cache
image.timestamp integer timestamp when cache created
image.compressed boolean is that cache compressed
image.data string base64 code, ugly text from your beauty images

getCacheSync

Deprecated

getSync

Get Cached image with Synchronous processing.

Example

var image = imageCache.getSync('http://domain/path/to/image.png');

API

API return same like .get()

setCache()

Deprecated

store()

store new image want to cache, write cache files into options.dir Directory. set cache is working with multiple images (Array).

imageCache.store(images, callback);

Params

Key Data Type
images array
callback function

Example Using Callback

let images = 'https://eladnava.com/content/images/2015/11/js-6.jpg';
imageCache.store(images, function(error) {
   console.log(error);
});

Example Using Promise

let images = 'https://eladnava.com/content/images/2015/11/js-6.jpg';
imageCache.store(images).then((result) {
    // do something when image stored
}).catch((e) => {
    console.log(e)
});

API Callback and Promise Catch

Key Data Type Description
error object this error came from fs.writeFile

flushCache()

Deprecated

flush()

Delete all cache files on your directory. this code will delete all cache on options.dir with extension name same as options.extname.

Example Using Callback

imageCache.flush(function(error, results) {
   if (error) {
      console.log(error);
   } else {
      console.log(results);
   }
});

Example Using Promise

imageCache.flush().then((results) => {
    console.log(results);
}).then((error) => {
    console.log(error);
});

API Callback

Key Data Type Description
results object details
results.deleted number total of deleted files
results.totalFiles number total files on directory
results.dir string Directory cache images

flushSync()

same like flush method, but using Synchronous processing.

Example

var results = imageCache.flushSync();

API

same like flush()

Key Data Type Description
results.error boolean error statement
results.message string error message

fetchImage()

Deprecated

fetch()

fetch() is a function to store cache and get cache data in one time. fetch() using Async processing for best performace. fetch() check your cache file first, if your image is not available in cache folder then this function will get image and return your cache data.

Params

Key Data Type Description
image string or array image or array of images

Example

var image = "http://path.to/image.jpg";

imageCache.fetch(image).then((images) => {
   images.forEach((image) => {
      console.log(image);

      // { ... }
   });
   console.log(images);

   // [ { ... } ]
}).catch((error) => {

});

API

Key Data Type Description
images array cache data array group
image object cache data object
image.error boolean cache data error indicator
image.url string image source url before transform to base64 format
image.hashFile string filename cache
image.timestamp integer timestamp when cache created
image.compressed boolean is that cache compressed
image.data string base64 code, ugly text from your beauty images
image.cache string cache status is "MISS" or "HIT"

What is MISS or HIT mean?

MISS

when your image is not available in the cache folder, image will be grab from image URL then cached on cache folder.

HIT

when your image is available in the cache folder, the image will be grab directly from cache folder.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].