{"id":18508112,"url":"https://github.com/imqueue/pg-cache","last_synced_at":"2026-02-02T00:35:30.689Z","repository":{"id":41667887,"uuid":"248283071","full_name":"imqueue/pg-cache","owner":"imqueue","description":"PostgreSQL managed cache on Redis for @imqueue-based service methods","archived":false,"fork":false,"pushed_at":"2025-09-04T15:26:35.000Z","size":2077,"stargazers_count":2,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-04T17:33:50.187Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imqueue.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-03-18T16:21:43.000Z","updated_at":"2025-09-04T15:26:38.000Z","dependencies_parsed_at":"2025-04-22T13:18:51.648Z","dependency_job_id":"ebd46291-e5df-420f-add2-6265b7d3b0e0","html_url":"https://github.com/imqueue/pg-cache","commit_stats":null,"previous_names":[],"tags_count":57,"template":false,"template_full_name":null,"purl":"pkg:github/imqueue/pg-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imqueue%2Fpg-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imqueue%2Fpg-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imqueue%2Fpg-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imqueue%2Fpg-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imqueue","download_url":"https://codeload.github.com/imqueue/pg-cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imqueue%2Fpg-cache/sbom","scorecard":{"id":486287,"data":{"date":"2025-08-11","repo":{"name":"github.com/imqueue/pg-cache","commit":"657e946d301c3e9489b181c62b9f2291370c6641"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.5,"checks":[{"name":"Code-Review","score":0,"reason":"Found 2/27 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":5,"reason":"6 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/build.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/imqueue/pg-cache/build.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/imqueue/pg-cache/build.yml/master?enable=pin","Warn: npmCommand not pinned by hash: .github/workflows/build.yml:26","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: GNU General Public License v3.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 5 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":6,"reason":"4 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-xffm-g5w8-qvg7","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T17:54:15.522Z","repository_id":41667887,"created_at":"2025-08-19T17:54:15.522Z","updated_at":"2025-08-19T17:54:15.522Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28997045,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-01T23:10:54.274Z","status":"ssl_error","status_checked_at":"2026-02-01T23:10:47.298Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-06T15:13:27.422Z","updated_at":"2026-02-02T00:35:30.684Z","avatar_url":"https://github.com/imqueue.png","language":"TypeScript","readme":"# @imqueue/pg-cache\n\nV3 uses sequelize v6.x\n\nLinks `@imqueue/pg-pubsub` with `@imqueue/tag-cache` and provides generic\nway to implement intellectual cache management based on database changes\nnotifications for @imqueue-based service methods.\n\n## Usage\n\n~~~typescript\nimport { IMQService, expose } from '@imqueue/rpc';\nimport { PgCache, cacheWith } from '@imqueue/pg-cache';\nimport { MyDbEntity } from './orm/models';\n\n@PgCache({\n    postgres: 'postgres://localhost:5432/db-name',\n    redis: { host: 'localhost', port: 6379 },\n    prefix: 'my-cool-service', // optional, if not passed will use class name as prefix\n})\nclass MyCoolService extends IMQService {\n    @expose()\n    @cacheWith({ channels: [MyDbEnity.tableName] })\n    public async listEntities(): Promise\u003cMyDbEntity\u003e {\n        return await MyDbEntity.findAll();\n    }\n}\n~~~\n\nWith the setup, described above first call to `MyCoolService.listEntities()`\nwill save method return value to cache and each next call will return cached\nvalue, stored in redis instead of making database query.\nEach function call is signed by a call signature, so if your method accepts \narguments which influence database query execution caching is made for each\nunique method call. Cached result will be automatically invalidated each time\neach table described in channels will trigger `INSERT`, `UPDATE` or `DELETE`. Or\nwhen TTL on a cache entity expires. By default TTL is 24 hours. If you want\ndifferent TTL to be used, do it as:\n\n~~~typescript\n@cacheWith({ channels: [MyDbEnity.tableName], ttl: 5 * 60 * 1000 })\n~~~\n\nIn this example TTL is set to 5 minutes. TTL should be provided in milliseconds.\n\n### Using @cacheBy\n\nSince v2.0.0 @cacheBy decorator introduced and helps simplify caching \ninvalidation definition for those service methods which rely on a root sequelize\nmodel output. In combination of passing the fields map to such service methods\nit will also provide more efficient caching for the method calls.\n\nTake a look at such example: \n\n~~~typescript\nimport { IMQService, expose } from '@imqueue/rpc';\nimport { PgCache, cacheBy } from '@imqueue/pg-cache';\nimport {\n    FieldsInput,\n    FindOptions,\n    OrderByInput,\n    PaginationInput,\n    query,\n} from '@imqueue/sequelize';\nimport { cacheConfig } from '../config';\nimport { MyDbEntity } from './orm/models';\nimport { MyDbEntityFilter } from './types';\nimport withRangeFilters = query.withRangeFilters;\nimport autoCountQuery = query.autoCountQuery;\nimport autoQuery = query.autoQuery;\nimport toWhereOptions = query.toWhereOptions;\nimport toLimitOptions = query.toLimitOptions;\nimport toOrderOptions = query.toOrderOptions;\n\n@PgCache(cacheConfig)\nclass MyCoolService extends IMQService {\n    @expose()\n    @cacheBy(MyDbEntity, { fieldsArg: 1 })\n    public async listEntities(\n        filter?: MyDbEntityFilter,\n        fields?: FieldsInput,\n        pageOptions?: PaginationInput,\n        orderBy?: OrderByInput,\n    ): Promise\u003c{ total: number, data: MyDbEntity[] }\u003e {\n        const where = toWhereOptions\u003cMyDbEntityFilter\u003e(\n            withRangeFilters(filter),\n            MyDbEntityFilter,\n        );\n        const countQuery = autoCountQuery(MyDbEntity, fields, where);\n        const findQuery = autoQuery\u003cFindOptions\u003e(\n            MyDbEntity, fields, where,\n            toLimitOptions\u003cMyDbEntity\u003e(pageOptions),\n            toOrderOptions(orderBy),\n        );\n        const [total, data] = await Promise.all([\n            MyDbEntity.count(countQuery),\n            MyDbEntity.findAll(findQuery),\n        ]);\n\n        return { total, data } as { total: number, data: MyDbEntity[] };\n    }\n}\n~~~\n\nBy doing so, `@cacheBy` will take care of invalidating only those queries\nwhich has selection of fields matching db changes events, so if the actual\nquery was not selecting some joined data, but there was a change only on that\njoined data - cache won't invalidate, as far as real selection was not \ninfluenced by a data change. And yes, it will automatically monitor\nall related to the root model entities for changes and match them with runtime\nselections. This makes caching more efficient and more obvious for\ndeveloper.\n\n### Extended channels API\n\n~~~typescript\nimport { cacheWith, ChannelOperation, ChannelPayload } from '@imqueue/pg-cache';\n\n// using simple filtering by operation\n@cacheWith({ channels: {\n    [MyDbEnity.tableName]: [ChannelOperation.UPDATE, ChannelOperation.INSERT]\n}})\n\n// or by using custom filtering function\n@cacheWith({ channels: {\n    [MyDbEnity.tableName]: (\n        payload: ChannelPayload, // payload caught from db event\n    ) =\u003e payload.operation === ChannelOperation.DELETE,\n}})\n~~~\n\n## Contributing\n\nAny contributions are greatly appreciated. Feel free to fork, propose PRs, open\nissues, do whatever you think may be helpful to this project. PRs which passes\nall tests and do not brake tslint rules are first-class candidates to be\naccepted!\n\n## License\n\nThis project is licensed under the GNU General Public License v3.0.\nSee the [LICENSE](LICENSE)\n\nHappy Coding!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimqueue%2Fpg-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimqueue%2Fpg-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimqueue%2Fpg-cache/lists"}