{"id":18010207,"url":"https://github.com/schteppe/node-mysql-querycache","last_synced_at":"2025-04-04T12:44:30.324Z","repository":{"id":11346988,"uuid":"13776675","full_name":"schteppe/node-mysql-querycache","owner":"schteppe","description":"Query caching to relax your MySQL database. Layer on top of node-mysql.","archived":false,"fork":false,"pushed_at":"2013-10-22T19:19:43.000Z","size":112,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-09T22:41:18.549Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/schteppe.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":"2013-10-22T14:59:57.000Z","updated_at":"2021-05-07T06:04:48.000Z","dependencies_parsed_at":"2022-09-04T04:21:28.601Z","dependency_job_id":null,"html_url":"https://github.com/schteppe/node-mysql-querycache","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/schteppe%2Fnode-mysql-querycache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schteppe%2Fnode-mysql-querycache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schteppe%2Fnode-mysql-querycache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schteppe%2Fnode-mysql-querycache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/schteppe","download_url":"https://codeload.github.com/schteppe/node-mysql-querycache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247182338,"owners_count":20897379,"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-10-30T02:13:19.190Z","updated_at":"2025-04-04T12:44:30.305Z","avatar_url":"https://github.com/schteppe.png","language":"JavaScript","readme":"node-mysql-querycache\n======================\nSimple, in-app query result caching to relax your MySQL database.\n\nBuilt upon [node-mysql](https://github.com/felixge/node-mysql).\n\n### Sample usage\n```js\nvar QueryCache = require('mysql-querycache').QueryCache;\nvar cache = new QueryCache({\n  timeout: 10 * 1000, // 10s\n  max:10, // Max cached results, if query changes over time\n});\ncache.query(conn,\"SELECT * FROM t WHERE id=?\",[1],function(err,result,isCached){\n    // Do something with the result\n});\n```\n\n### QueryCache class options\nSyntax:\n```\nnew QueryCache(options)\n```\n\n##### timeout\nAge (in milliseconds) of an \"old\" cache that can be discareded.\n\n##### max\nThe maximum number of cached results.\n\n##### connection\nIf you run cache.query() without the first connection parameter, it will use this connection object instead.\n\n### .query([connection,] query [,values] , callback)\nRun a cached mysql query.\n\nThe first time the query is done, it will make a database request. Second time, it will reuse the result from the first query, if the following conditions hold:\n\n* The cached result is not older than ```options.timeout``` milliseconds\n* The cached result has not beed removed due to exceeded max cache (see ```options.max```).\n\n### Race conditions\n\nIf a race condition occurs, where an identical second query is requested before the first one has finished, QueryCache will make sure that the second query waits for the first result to become cached.\n\n##### Example\n```js\ncache.query(\"SELECT * FROM hugeTable\",function(err,result,isCached){\n    console.log(\"first\",isCached);\n});\ncache.query(\"SELECT * FROM hugeTable\",function(err,result,isCached){\n    console.log(\"second\",isCached);\n});\n```\nOutput:\n```\nfirst false\nsecond true\n```\nThe important thing to note here is that the second query will wait for the first to finish and return the same result.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschteppe%2Fnode-mysql-querycache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fschteppe%2Fnode-mysql-querycache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschteppe%2Fnode-mysql-querycache/lists"}