{"id":19029333,"url":"https://github.com/guardian/etag-caching","last_synced_at":"2026-03-06T19:24:08.012Z","repository":{"id":185284677,"uuid":"673290125","full_name":"guardian/etag-caching","owner":"guardian","description":"Library for in-memory ETag-aware caching of services like AWS S3, saving CPU \u0026 bandwidth","archived":false,"fork":false,"pushed_at":"2026-03-05T11:34:05.000Z","size":1214,"stargazers_count":2,"open_issues_count":5,"forks_count":1,"subscribers_count":23,"default_branch":"main","last_synced_at":"2026-03-05T15:38:03.519Z","etag":null,"topics":["cache","etag","library","production","scala"],"latest_commit_sha":null,"homepage":"","language":"Scala","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/guardian.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":".github/CODEOWNERS","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":"2023-08-01T09:49:13.000Z","updated_at":"2026-03-05T11:34:08.000Z","dependencies_parsed_at":"2023-08-01T11:08:28.490Z","dependency_job_id":"a87aef87-2bc6-42dc-aea9-1c396581dfc9","html_url":"https://github.com/guardian/etag-caching","commit_stats":null,"previous_names":["guardian/etag-caching"],"tags_count":188,"template":false,"template_full_name":null,"purl":"pkg:github/guardian/etag-caching","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guardian%2Fetag-caching","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guardian%2Fetag-caching/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guardian%2Fetag-caching/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guardian%2Fetag-caching/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guardian","download_url":"https://codeload.github.com/guardian/etag-caching/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guardian%2Fetag-caching/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30193249,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T19:07:06.838Z","status":"ssl_error","status_checked_at":"2026-03-06T18:57:34.882Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["cache","etag","library","production","scala"],"created_at":"2024-11-08T21:13:52.974Z","updated_at":"2026-03-06T19:24:07.969Z","avatar_url":"https://github.com/guardian.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# etag-caching\n_Only fetch what's needed, only parse what you don't already have_\n\n[![core Scala version support](https://index.scala-lang.org/guardian/etag-caching/core/latest-by-scala-version.svg?platform=jvm)](https://index.scala-lang.org/guardian/etag-caching/core)\n[![aws-s3-sdk-v2 Scala version support](https://index.scala-lang.org/guardian/etag-caching/aws-s3-sdk-v2/latest-by-scala-version.svg?platform=jvm)](https://index.scala-lang.org/guardian/etag-caching/aws-s3-sdk-v2)\n[![CI](https://github.com/guardian/etag-caching/actions/workflows/ci.yml/badge.svg)](https://github.com/guardian/etag-caching/actions/workflows/ci.yml)\n[![Release](https://github.com/guardian/etag-caching/actions/workflows/release.yml/badge.svg)](https://github.com/guardian/etag-caching/actions/workflows/release.yml)\n\nMany services (eg Amazon S3) include the [`ETag`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag)s HTTP response header\nin their replies - the ETag is a service-generated hash of the content requested.\nIf the client retains the ETag, they can send it in a [`If-None-Match`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-None-Match) HTTP request header in subsequent requests - if the service knows\nthe content still has the same ETag, the content hasn't changed, and the service will respond with a blank \nHTTP [`304 Not Modified`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/304) status code - no body will be returned, as the\nservice knows you already have the content - this saves network bandwidth, and as there's no new content-parsing required for the client,\nthe client will have lower CPU requirements as well!\n\nTo make use of this as a client, you need an `ETagCache` - one where the latest ETags are stored. Although the cache could simply be storing the raw\ncontent sent by the service, for an in-memory cache it's usually optimal to store a _parsed_ representation of the data - to save having\nto parse the data multiple times. Consequently, `ETagCache` has a `Loader` that holds the two concerns of *fetching* \u0026 *parsing*.\n\n### Usage\n\nThe main API entry point is the `com.gu.etagcaching.ETagCache` class.\n\n#### Examples\n\n* https://github.com/guardian/frontend/pull/26338\n* https://github.com/guardian/facia-scala-client/pull/287\n\nThis example (taken from [`S3ObjectFetchingTest`](https://github.com/guardian/etag-caching/blob/main/aws-s3/aws-sdk-v2/src/test/scala/com/gu/etagcaching/aws/sdkv2/s3/S3ObjectFetchingTest.scala))\nshows an `ETagCache` setup for fetching-and-parsing compressed XML from S3:\n\n```scala\nimport com.gu.etagcaching.ETagCache\nimport com.gu.etagcaching.aws.s3.ObjectId\nimport com.gu.etagcaching.aws.sdkv2.s3.S3ObjectFetching\nimport com.gu.etagcaching.aws.sdkv2.s3.response.Transformer.Bytes\nimport software.amazon.awssdk.services.s3.S3AsyncClient\nimport scala.util.Using\n\nval s3Client: S3AsyncClient = ???\ndef parseFruit(is: InputStream): Fruit = ???\n\nval fruitCache = new ETagCache[ObjectId, Fruit](\n  S3ObjectFetching(s3Client, Bytes).thenParsing {\n    bytes =\u003e Using(new GZIPInputStream(bytes.asInputStream()))(parseFruit).get\n  },\n  AlwaysWaitForRefreshedValue,\n  _.maximumSize(500).expireAfterAccess(1.hour)\n)\n\nfruitCache.get(exampleS3id) // Future[Fruit]\n```\n\n### Loading = Fetching + Parsing\n\n```mermaid\nflowchart LR\nsubgraph \"Loading[K,V]\"\ndirection LR\nfetching(\"fetching: Fetching[K, Response]\")\nparsing(\"parsing: Response =\u003e V\")\nfetching --\"response\"--\u003e parsing\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguardian%2Fetag-caching","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguardian%2Fetag-caching","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguardian%2Fetag-caching/lists"}