{"id":18059040,"url":"https://github.com/nyancodeid/image-cache","last_synced_at":"2025-04-11T08:33:20.146Z","repository":{"id":41454801,"uuid":"95016044","full_name":"nyancodeid/image-cache","owner":"nyancodeid","description":"NodeJS Image cache with Base64 format","archived":false,"fork":false,"pushed_at":"2021-09-26T04:52:10.000Z","size":109,"stargazers_count":20,"open_issues_count":1,"forks_count":11,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T06:03:53.754Z","etag":null,"topics":["cache","callback","image-cache","nodejs"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/image-cache","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nyancodeid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-21T14:59:04.000Z","updated_at":"2024-10-17T14:15:37.000Z","dependencies_parsed_at":"2022-08-25T03:52:22.523Z","dependency_job_id":null,"html_url":"https://github.com/nyancodeid/image-cache","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nyancodeid%2Fimage-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nyancodeid%2Fimage-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nyancodeid%2Fimage-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nyancodeid%2Fimage-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nyancodeid","download_url":"https://codeload.github.com/nyancodeid/image-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248361626,"owners_count":21090944,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","callback","image-cache","nodejs"],"created_at":"2024-10-31T03:10:02.145Z","updated_at":"2025-04-11T08:33:20.119Z","avatar_url":"https://github.com/nyancodeid.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# image-cache\n[![Build Status](https://travis-ci.org/nyancodeid/image-cache.svg?branch=master)](https://travis-ci.org/nyancodeid/image-cache) [![npm version](https://badge.fury.io/js/image-cache.svg)](https://badge.fury.io/js/image-cache)  \n\nPowerful image cache for NodeJS\n\n## What is image-cache?\n`image-cache` is nodejs module for cache image and serve with base64 format. `image-cache` using \nAsynchronous calls for best Performance.\n\n## New\n- Compressed options default is `false`\n- Library Core now using Javascript Classes\n- New syntax and function\n- Now `image-cache` using [google proxy cache](https://gist.github.com/coolaj86/2b2c14b1745028f49207) for best caching.\n\n## Installation\nto install `image-cache` on your project, you can use NPM and Yarn with the following command, \n\n### NPM\n```bash\nnpm install --save image-cache \n```\n\n### Yarn\n```bash\nyarn add image-cache\n```\n\n## Usage\nStart using `image-cache` \n\n```javascript\nconst imageCache = require('image-cache');\n```\n\n## API\n\n### setOptions\nis a function to replace options from `default options`. this function not returning something.\nfor using this function, add this code after defining all variable.\n\n```javascript\nimageCache.setOptions({\n   compressed: false\n\n   // write your custom options here\n});\n```\n#### API \n| Key          | Data Type    | Default Value    | Description |\n| :------------- | :----------- | :------------- | :------------- |\n| `dir` | `string` | `path.join(__dirname, 'cache/')` | directory root for cached files |\n| `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 |\n| `extname` | `string` | `.cache` | file extension for your cache files |\n| `googleCache` | `boolean` | `true` | using google cache proxy |\n\n### isCached()\nCheck is your image already cached or not. this function need 2 params.\n\n```javascript\nimageCache.isCached(url, callback);\n```\n\n#### Params\n| Key          | Data Type    |\n| :------------- | :----------- |\n| `url` | `string` | \n| `callback` | `function` | \n\n#### Example Using Callback\n```javascript\nimageCache.isCached(url, (exist) =\u003e {\n   if (exist) {\n      // do something with cached image\n   }\n});\n```\n#### Example Using Promise\n```javascript\nimageCache.isCached(url).then((exist) =\u003e {\n   if (exist) {\n      // do something with cached image\n   }\n});\n```\n\n### isCachedSync()\nCheck is your image is cached with Synchronous processing. return as `boolean`\n\n#### Example\n\n```javascript\nvar exists = imageCache.isCachedSync(url);\n```\n#### API\n| Params         | Data Type    | Description    |\n| :------------- | :----------- | :------------- | \n| `url` | `string` | url of your image |\n\n\n### getCache\nDeprecated\n\n### get()\nGet cached image\n\n#### Example\n```javascript\nimageCache.get(url, (error, image) =\u003e {\n   console.log(image);\n\n   // do something with image\n});\n```\n#### API Callback\n| Key          | Data Type    | Description    |\n| :------------- | :----------- | :------------- | \n| `image` | `object` | cache data object |\n| `image.error`  | `boolean`   | cache data error indicator |\n| `image.url`    | `string`   | image source url before transform to base64 format |\n| `image.hashFile` | `string` | filename cache |\n| `image.timestamp` | `integer` | timestamp when cache created |\n| `image.compressed` | `boolean` | is that cache compressed |\n| `image.data` | `string` | base64 code, ugly text from your beauty images |\n\n\n### getCacheSync\nDeprecated\n\n### getSync\nGet Cached image with Synchronous processing.\n\n#### Example\n\n```javascript\nvar image = imageCache.getSync('http://domain/path/to/image.png');\n```\n\n#### API\nAPI return same like `.get()`\n\n### setCache()\nDeprecated\n\n### store()\nstore new image want to cache, write cache files into `options.dir` Directory. set cache is working with multiple images (Array). \n\n```javascript\nimageCache.store(images, callback);\n```\n\n#### Params\n| Key          | Data Type    |\n| :------------- | :----------- |\n| `images` | `array`|`string` | \n| `callback` | `function` | \n\n#### Example Using Callback\n```javascript\nlet images = 'https://eladnava.com/content/images/2015/11/js-6.jpg';\nimageCache.store(images, function(error) {\n   console.log(error);\n});\n```\n#### Example Using Promise\n```javascript\nlet images = 'https://eladnava.com/content/images/2015/11/js-6.jpg';\nimageCache.store(images).then((result) {\n    // do something when image stored\n}).catch((e) =\u003e {\n    console.log(e)\n});\n```\n\n#### API Callback and Promise Catch\n| Key          | Data Type    | Description    |\n| :------------- | :----------- | :------------- | \n| `error` | `object` | this error came from `fs.writeFile`  |\n\n### flushCache()\nDeprecated\n\n### flush()\nDelete all cache files on your directory. this code will delete all cache on `options.dir` with extension name same as `options.extname`. \n\n#### Example Using Callback\n```javascript\nimageCache.flush(function(error, results) {\n   if (error) {\n      console.log(error);\n   } else {\n      console.log(results);\n   }\n});\n```\n#### Example Using Promise\n```javascript\nimageCache.flush().then((results) =\u003e {\n    console.log(results);\n}).then((error) =\u003e {\n    console.log(error);\n});\n```\n\n#### API Callback\n| Key          | Data Type    | Description    |\n| :------------- | :----------- | :------------- |\n| `results` | `object` | details |\n| `results.deleted` | `number` | total of deleted files |\n| `results.totalFiles` | `number` | total files on directory |\n| `results.dir` | `string` | Directory cache images |\n\n### flushSync()\nsame like `flush` method, but using Synchronous processing.\n\n#### Example\n\n```javascript\nvar results = imageCache.flushSync();\n```\n\n#### API\nsame like `flush()`\n\n| Key          | Data Type    | Description    |\n| :------------- | :----------- | :------------- |\n| `results.error` | `boolean` | error statement |\n| `results.message` | `string` | error message |\n\n### fetchImage()\nDeprecated\n\n### fetch()\n`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.\n\n#### Params\n| Key          | Data Type    | Description    |\n| :------------- | :----------- | :------------- | \n| `image` | `string` or `array` | image or array of images | \n\n#### Example\n\n```javascript\nvar image = \"http://path.to/image.jpg\";\n\nimageCache.fetch(image).then((images) =\u003e {\n   images.forEach((image) =\u003e {\n      console.log(image);\n\n      // { ... }\n   });\n   console.log(images);\n\n   // [ { ... } ]\n}).catch((error) =\u003e {\n\n});\n```\n\n#### API\n| Key          | Data Type    | Description    |\n| :------------- | :----------- | :------------- | \n| `images` | `array` | cache data array group |\n| `image` | `object` | cache data object |\n| `image.error`  | `boolean`   | cache data error indicator |\n| `image.url`    | `string`   | image source url before transform to base64 format |\n| `image.hashFile` | `string` | filename cache |\n| `image.timestamp` | `integer` | timestamp when cache created |\n| `image.compressed` | `boolean` | is that cache compressed |\n| `image.data` | `string` | base64 code, ugly text from your beauty images |\n| `image.cache` | `string` | cache status is \"MISS\" or \"HIT\" |\n\n## What is MISS or HIT mean?\n\n### MISS\nwhen your image is not available in the cache folder, image will be grab from image URL then cached on cache folder.\n\n### HIT\nwhen your image is available in the cache folder, the image will be grab directly from cache folder.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnyancodeid%2Fimage-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnyancodeid%2Fimage-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnyancodeid%2Fimage-cache/lists"}