Skip to content

Add API Caching #3

@asg017

Description

@asg017

Currently API calls are made everytime they're requested, but it seems like we could cache these responses. Example:

$ curl 'https://api.open.fec.gov/v1/filings/?api_key=DEMO_KEY&cycle=2026&committee_id=C00900449' -I -L
HTTP/2 200
date: Fri, 17 Oct 2025 04:31:26 GMT
content-type: application/json
content-length: 7752
vary: Accept-Encoding
access-control-allow-origin: *
age: 0
cache-control: public, max-age=3600
...

That max-age=3600 is a hint for browsers that they can cache responses for 60 minutes. We don't cache for the libfec CLI, but maybe we could.

Notably the efile/filings endpoint does not cache:

$ curl 'https://api.open.fec.gov/v1/efile/filings/?api_key=DEMO_KEY&cycle=2026&committee_id=C00900449' -I -L
HTTP/2 200
date: Fri, 17 Oct 2025 04:30:42 GMT
content-type: application/json
content-length: 1851
vary: Accept-Encoding
access-control-allow-origin: *
age: 0
cache-control: public, max-age=0
...

Notably the max-age=0 header. The caching strategy is actually defined here:

https://github.com/fecgov/openFEC/blob/97bdf5af530e385ba9e8e54cabc8dc83819f16f0/webservices/rest.py#L366-L398

This came up because if I re-run the same export over and over, my precious DEMO_TOKEN requests would get eaten up fast, even through it made the same API calls every time.

Could be a new .api-cache.db file inside the cache directory, like `.bulk-data.db.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions