{"id":16049038,"url":"https://github.com/lovell/nginx-cache","last_synced_at":"2025-03-18T04:31:05.960Z","repository":{"id":27735577,"uuid":"31223234","full_name":"lovell/nginx-cache","owner":"lovell","description":"Node.js module to find files in an Nginx cache based on partial URL keys","archived":false,"fork":false,"pushed_at":"2017-10-08T09:17:36.000Z","size":14,"stargazers_count":25,"open_issues_count":1,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-10T08:48:34.558Z","etag":null,"topics":["cache","javascript","nginx","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lovell.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":"2015-02-23T18:44:50.000Z","updated_at":"2022-12-15T18:23:18.000Z","dependencies_parsed_at":"2022-09-03T07:12:21.090Z","dependency_job_id":null,"html_url":"https://github.com/lovell/nginx-cache","commit_stats":null,"previous_names":["dimensio/nginx-cache"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovell%2Fnginx-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovell%2Fnginx-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovell%2Fnginx-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lovell%2Fnginx-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lovell","download_url":"https://codeload.github.com/lovell/nginx-cache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244156621,"owners_count":20407539,"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","javascript","nginx","nodejs"],"created_at":"2024-10-09T00:12:44.087Z","updated_at":"2025-03-18T04:31:05.346Z","avatar_url":"https://github.com/lovell.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nginx-cache\n\nA Node.js module that recursively scans\nthe directories and files of an _Nginx_ cache\nas efficiently as possible\nlooking for partial URL key matches\nbased on a regular expression.\n\n## Install\n\n```sh\nnpm install nginx-cache\n```\n\n```sh\nyarn add nginx-cache\n```\n\n## Usage example\n\nPurge all CSS files from an Nginx cache:\n\n```javascript\nconst NginxCache = require('nginx-cache');\n\nNginxCache('/var/www/cache')\n  .find(/.css$/)\n  .on('match', function(file, url) {\n    console.log('Attempting to remove cached version of ' + url);\n    fs.unlink(file, function(err) {\n      if (err) {\n        console.log(err.message);\n      }\n    });\n  })\n  .on('error', function(err) {\n    console.log(err.message);\n  })\n  .on('finish', function() {\n    console.log('Done');\n  });\n```\n\n## API\n\n### NginxCache(directory)\n\nConstructor to which further methods are chained.\n\n* `directory` is the path to the _Nginx_ cache, as provided to its `proxy_cache_path` directive.\n\n### find(pattern)\n\n* `pattern` is an instance of a standard JavaScript `RegExp` object.\n\n### on(event, listener)\n\nRegister a function to listen for the given event, where:\n\n* `event` is a String containing the name of the event (see below), and\n* `listener` is a function to call when the event is emitted.\n\n#### Event: 'match'\n\nThe `match` event is emitted when a cache file matching the `pattern` passed to `find()` is found.\n\nThe event attributes are `file, url` where:\n\n* `file` is the full path to the matching cache file, and\n* `url` is the full cache key that matched the pattern.\n\n#### Event: 'finish'\n\nThe `finish` event is emitted when all cache directories and files have been scanned.\nNo further events are emitted after this.\n\n#### Event: 'error'\n\nThe `error` event is emitted when a non-ignorable problem occurs,\ne.g. lack of permission to read files in the cache directory.\n\n#### Event: 'warn'\n\nThe `warn` event is emitted when an ignorable problem occurs,\ne.g. the Nginx cache manager deleted a file.\n\n## Alternatives\n\nIf you know the complete, original cache key\nthen the commercial _Plus_ version of _Nginx_ provides a\n[proxy_cache_purge](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_purge) directive,\nwhich may be more suitable.\n\n## Licence\n\nCopyright 2015, 2017 Dispatches LLP.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0.html)\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flovell%2Fnginx-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flovell%2Fnginx-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flovell%2Fnginx-cache/lists"}