Skip to content

Inconsistent HTTP caching: properties and SKOS endpoints missing check_last_modified #237

Description

@alexskr

Summary

While reviewing controllers, found that HTTP caching (check_last_modified / check_last_modified_segment / check_last_modified_collection) is applied inconsistently. Some read endpoints emit Last-Modified / Cache-Control and support 304 Not Modified revalidation; others don't, so clients re-fetch full payloads unnecessarily.

There are two distinct root causes — one is a controller-layer gap, the other is a model-layer gap.

Background

check_last_modified* lives in helpers/http_cache_helper.rb. It only works for models registered as cacheable resources — i.e. models that declare cache_timeout (and usually cache_segment_instance) in ontologies_linked_data. LinkedData::HTTPCache::CacheableResource is mixed into every model via base.rb, but max_age reads cache_settings[:cache_timeout].first, so a model that never calls cache_timeout is not a functioning cacheable resource.

Model cache_timeout declared? Controller calls check_last_modified*?
Class yes (86400) yes
Instance (named_individual) yes (14400) yes
OntologySubmission yes (3600) yes
SKOS::Collection yes (14400) no
SKOS::Scheme yes (14400) no
SKOS::Label (skosxl) no no
property models (object/datatype/annotation/ontology_property) no no

Gap 1 — controller layer (models already cacheable)

SKOS::Collection and SKOS::Scheme models already declare cache_timeout 14400, but collections_controller and schemes endpoints never call check_last_modified*. These were added in the 2025-06 SKOS batch (collections/schemes/labels) which landed without wiring caching into the controllers.

  • Add check_last_modified* to the SKOS collections/schemes read endpoints (no model change required).

Gap 2 — model layer (not cacheable at all)

Neither the property models nor SKOS::Label declare cache_timeout, so they are not cacheable resources. The properties_controller has had no caching since it was created (2013); skos_xl_label_controller is new (2025) and the Label model was never made cacheable.

  • Decide whether property reads and SKOS XL label reads should be HTTP-cached.
  • If yes: add cache_timeout / cache_segment_instance to the relevant models in ncbo/ontologies_linked_data, then call check_last_modified* in the controllers here.

Notes

  • Cross-repo: Gap 2 requires model changes in ncbo/ontologies_linked_data first.
  • check_last_modified* must only be invoked on GET routes (it can short-circuit with 304); do not add it to mixed-method handlers blindly.
  • Discovered while doing the before-filter / boilerplate dedup work on the classes/instances controllers.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions