{"id":21558101,"url":"https://github.com/koopjs/koop-cache-redis","last_synced_at":"2025-04-10T10:41:19.096Z","repository":{"id":57125438,"uuid":"82694191","full_name":"koopjs/koop-cache-redis","owner":"koopjs","description":null,"archived":false,"fork":false,"pushed_at":"2023-03-17T21:10:58.000Z","size":50,"stargazers_count":1,"open_issues_count":6,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T09:38:14.323Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koopjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-21T15:15:13.000Z","updated_at":"2019-09-12T18:20:47.000Z","dependencies_parsed_at":"2023-01-25T21:45:15.488Z","dependency_job_id":null,"html_url":"https://github.com/koopjs/koop-cache-redis","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koopjs%2Fkoop-cache-redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koopjs%2Fkoop-cache-redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koopjs%2Fkoop-cache-redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koopjs%2Fkoop-cache-redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koopjs","download_url":"https://codeload.github.com/koopjs/koop-cache-redis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247987284,"owners_count":21028895,"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":[],"created_at":"2024-11-24T08:13:58.875Z","updated_at":"2025-04-10T10:41:19.074Z","avatar_url":"https://github.com/koopjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Koop Redis Cache\n[![Build Status](https://travis-ci.org/koopjs/koop-cache-redis.svg?branch=master)](https://travis-ci.org/koopjs/koop-cache-redis) [![Greenkeeper badge](https://badges.greenkeeper.io/koopjs/koop-cache-redis.svg)](https://greenkeeper.io/)\n\n## Usage\n\nTo use this cache:\nFirst: npm install @koopjs/cache-redis\nThen: configure your host. In your config file\n\nconfig/production.json\n```json\n{\n  \"cache\": {\n    \"redis\": {\n      \"host\": \"redis://localhost:6379\"\n    }\n  }\n}\n```\nIf using environment variables like\nconfig/custom-environment-variables.json\n```json\n{\n  \"cache\": {\n    \"redis\": {\n      \"host\": \"KOOP_REDIS_HOST\"\n    }\n  }\n}\n```\nThen you must export the REDIS_HOST variable into your ENV e.g.\n`export KOOP_REDIS_HOST=\"redis://localhost:6379\"`\n\nThen require and register the redis cache with Koop\n\n```js\nconst Koop = require('koop')\nconst koop = new Koop()\nconst config = require('config')\nconst cache = require('@koopjs/cache-redis')\nkoop.register(cache)\n```\n\n## Cache API\n\n### `insert`\nInsert geojson into the cache\n\nNote: A metadata entry will be created automatically. It can be populated from an object on the inserted geojson.\n\n```js\nconst geojson = {\n  type: 'FeatureCollection',\n  features: [],\n  metadata: { // Metadata is an arbitrary object that will be stored in the catalog under the same key as the geojson\n    name: 'Example GeoJSON',\n    description: 'This is geojson that will be stored in the cache'\n  }\n}\n\nconst options = {\n  ttl: 1000 // The TTL option is measured in seconds, it will be used to set the `expires` field in the catalog entry\n}\n\ncache.insert('key', geojson, options, err =\u003e {\n  // This function will call back with an error if there is already data in the cache using the same key\n})\n```\n\n### `append`\nAdd features to an existing geojson feature collection in the cache\nNote:\n\n```js\nconst geojson = {\n  type: 'FeatureCollection',\n  features: []\n}\ncache.append('key', geojson, err =\u003e {\n  // This function will call back with an error if the cache key does not exist\n})\n```\n\n### `update`\nUpdate a cached feature collection with new features.\nThis will completely replace the features that are in the cache, but the metadata doc will remain in the catalog.\n\n```js\nconst geojson = {\n  type: 'FeatureCollection',\n  features: []\n}\n\nconst options = {\n  ttl: 1000\n}\ncache.update('key', geojson, options, err =\u003e {\n  // This function will call back with an error if the cache key does not exist\n})\n```\n\n### `upsert`\nUpdate a cached feature collection with new features or insert if the features are not there.\n\n```js\nconst geojson = {\n  type: 'FeatureCollection',\n  features: []\n}\n\nconst options = {\n  ttl: 1000\n}\n\ncache.upsert('key', geojson, options, err =\u003e {\n  // This function will call back with an error if the cache key does not exist\n})\n```\n\n### `retrieve`\nRetrieve a cached feature collection\n\n```js\nconst options = {} // For now there are no options on retrieve. This is meant for compatibility with the general cache API\ncache.retrieve('key', options, (err, geojson) =\u003e {\n  /* This function will call back with an error if there is no geojson in the cache\n  The geojson returned will contain the metadata document from the catalog\n  {\n    type: 'FeatureCollection',\n    features: [],\n    metadata: {}\n  }\n  */\n})\n```\n\n### `delete`\nRemove a feature collection from the cache\n\n```js\ncache.delete('key', err =\u003e {\n  // This function will call back with an error if there was nothing to delete\n})\n```\n\n### `createStream`\nCreate a stream of features from the cache\n\n```js\ncache.createStream('key', options)\n.pipe(/* do something with the stream of geojson features emitted one at a time */)\n```\n\n## Catalog API\nThe catalog stores metadata about items that are in the cache.\n\n### `catalog.insert`\nAdd an arbitrary metadata document to the cache.\nNote: This is called automatically by `insert`\n\n```js\nconst metadata = {\n  name: 'Standalone metadata',\n  status: 'Processing',\n  description: 'Metadata that is not attached to any other data in the cache'\n}\n\ncache.catalog.insert('key', metadata, err =\u003e {\n  // this function will call back with an error if there is already a metadata document using the same key\n})\n```\n\n### `catalog.update`\nUpdate a metadata entry\n\n```js\nconst original = {\n  name: 'Doc',\n  status: 'Processing'\n}\ncache.catalog.insert('key', original)\n\nconst update = {\n  status: 'Cached'\n}\n\ncache.catalog.update('key', update, err =\u003e {\n  // this function will call back with an error if there is no metadata in the catalog using that key\n})\n\ncache.catalog.retrieve('key', (err, metadata) =\u003e {\n  /*\n    Updates are merged into the existing metadata document\n    Return value will be:\n    {\n      name: 'Doc',\n      status: 'Cached'\n    }\n  */\n})\n```\n\n### `catalog.retrieve`\nRetrieve a metadata entry from the catalog\n\n```js\ncache.catalog.retrieve('key', (err, metadata) =\u003e {\n  // This function will call back with an error if there is no metadata stored under the given key\n  // Or else it will call back with the stored metadata doc\n})\n```\n\n### `catalog.delete`\nRemove a catalog entry from the catalog\nNote: This cannot be called if data is in the cache under the same key\n\n```js\ncache.catalog.delete('key', err =\u003e {\n  // This function will call back with an error if there is nothing to delete or if there is still data in the cache using the same key\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoopjs%2Fkoop-cache-redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoopjs%2Fkoop-cache-redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoopjs%2Fkoop-cache-redis/lists"}