{"id":28454080,"url":"https://github.com/jlecomte/context-cache","last_synced_at":"2025-06-28T05:31:28.448Z","repository":{"id":6539340,"uuid":"7780678","full_name":"jlecomte/context-cache","owner":"jlecomte","description":"Context cache utility","archived":false,"fork":false,"pushed_at":"2013-05-16T22:17:31.000Z","size":187,"stargazers_count":4,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-06T18:53:15.579Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jlecomte.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-01-23T18:18:29.000Z","updated_at":"2022-07-19T07:50:09.000Z","dependencies_parsed_at":"2022-09-15T18:40:27.083Z","dependency_job_id":null,"html_url":"https://github.com/jlecomte/context-cache","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jlecomte/context-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlecomte%2Fcontext-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlecomte%2Fcontext-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlecomte%2Fcontext-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlecomte%2Fcontext-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jlecomte","download_url":"https://codeload.github.com/jlecomte/context-cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlecomte%2Fcontext-cache/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262381323,"owners_count":23302215,"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":"2025-06-06T18:40:42.412Z","updated_at":"2025-06-28T05:31:28.442Z","avatar_url":"https://github.com/jlecomte.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Context cache\n\nOverview\n========\n\nRequests are often served differently depending on their \"context\".\nThe context of a request is composed of multiple dimensions.\nHere are some examples of common dimensions:\n\n-   environment   { production, staging, regression, development, etc. }\n-   lang          { en-US, en-GB, fr-FR, fr-CA, etc. }\n-   device        { desktop, tablet, phone, etc. }\n-   partner       { foo, bar, baz, etc. }\n-   experiment    { A, B, C, etc. }\n\nOftentimes, meta-data necessary to handle a request has to be computed based on\nits context. That computing can be expensive, so the result is usually cached.\nUnfortunately, as you can see, the number of contexts can be extremely high\nsince it is the combination of the values each dimension can take. This results\nin a very large cache containing a large number of objects. This in turns slows\ndown garbage collection (GC). At Yahoo!, we've seen instances where GC ends up\nrepresenting 70% of the average time needed to serve a request! Additionally,\nin some cases, only a small number of contexts may really be needed to serve a\nlarge percentage of traffic. For example, at Yahoo! Search, a node may cache\nmeta-data for 1,000+ contexts, but we noticed that the 100 most requested\ncontexts serve over 98% of our traffic.\n\nThis utility module solves this specific issue by caching data only for the\nmost requested contexts. This will result in low latency for most of your\ntraffic and low memory consumption, which is a requirement for efficient GC.\n\nUsage\n=====\n\nInstall the `context-cache` npm package:\n\n    npm install context-cache\n\nYou can then create a `ContextCache` instance in your application code:\n\n    var ContextCache = require('./context-cache');\n    var cc = ContextCache.create();\n\nYou can pass configuration settings to `create`:\n\n    var cc = ContextCache.create({\n        maxCacheSize: 200,\n        cacheHitThreshold: 10,\n        storeObjectsSerialized: true,\n        hotcacheTTL: 300,\n        isolationMode: 'clone'\n    });\n\nYou can then use that instance to store/retrieve in/from the cache:\n\n    var ctx = JSON.stringify(context);\n    cc.set(ctx, data);\n    var data = cc.get(ctx);\n\nFinally, you can obtain information about the cache itself:\n\n    console.log(cc.getInfo());\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlecomte%2Fcontext-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjlecomte%2Fcontext-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlecomte%2Fcontext-cache/lists"}