Skip to content

Key the cloud engines' cache on the request's evidence and apply the Cloud Request Engine's cache rules - #300

Merged
jwrosewell merged 1 commit into
rcfrom
fix/cloud-engine-cache-key
Dec 1, 2026
Merged

jwrosewell merged 1 commit into
rcfrom
fix/cloud-engine-cache-key

Conversation

@jwrosewell

Copy link
Copy Markdown
Contributor

Summary

The cache setting of the cloud pipeline builders now goes on the Cloud Request Engine, which keys the cache on the evidence it sends and applies its own cache rules. A cloud engine (CloudEngine and every engine built on it, DerivedCloud included) refuses a cache and never uses one of its own.

Why

A cloud engine accepts no evidence (CloudEngine.get_evidence_key_filter returns an empty list), so there is no key to use in a results cache of its own. The Cloud Aspect Engine specification says the same under "Configuration options", recommends the cache goes on the Cloud Request Engine, and lets an implementation restrict the option. .NET's cloud pipeline builders already put their results cache on the Cloud Request Engine (CloudPipelineBuilderBase.Build).

The Cloud Request Engine's cache rules are in cloudrequestengine.py (process, bypasses_cache and is_cacheable). A response made for one visitor (a 51Did, a sealed HumanConfidence result, the browser tests' script) is neither stored nor served, and a request that carries a session id, a sequence, JA4 or HTTP/2 settings, or a sealed result to redeem always goes to the cloud service.

What changed

  • pipeline/fiftyone_pipeline_cloudrequestengine/.../cloudengine.py

    • CloudEngine.set_cache raises an exception that names the Cloud Request Engine, as the on-premise engines already refuse a cache.
    • CloudEngine.process calls process_internal with no cache of the engine's own, whatever the engine holds.
  • humanconfidence.py: DerivedCloud inherits both, so a redeemed Human Confidence result is never stored or served again. Its class documentation says so.

  • The cache setting of these builders now calls set_cache on the Cloud Request Engine rather than on the cloud engine, and their documentation says so:

    • DeviceDetectionCloudPipelineBuilder and DeviceDetectionPipelineBuilder (cloud branch)
    • IpIntelligenceCloudPipelineBuilder and IpIntelligencePipelineBuilder (cloud branch)
    • LocationPipelineBuilder

    The on-premise branches of the two combined builders are unchanged, because the on-premise engines' constructors already raise when given a cache.

Behaviour to know about

  • A caller that called set_cache on a cloud engine directly now gets the exception, which says to add the cache to the Cloud Request Engine instead.
  • With the JavaScript builder on, which is the builders' default, the sequence element gives every request a session id, and the Cloud Request Engine sends a request carrying a session id to the cloud service every time. So the cache answers repeated requests only in a pipeline built with add_javascript_builder=False. The builders' documentation now says this.

Tests

Each new test fails on rc (df9a59c) and passes on this branch. I ran them both ways by setting the source change aside and running the same tests.

  • test_builder_cache.py in fiftyone_devicedetection_cloud, fiftyone_ipintelligence_cloud and location, and in fiftyone_devicedetection_examples and fiftyone_ipintelligence_examples for the combined builders, which have no test packages of their own. Against a stand-in for the cloud service, each checks that the cache is on the Cloud Request Engine and not on the cloud engine, that two different requests (User-Agents, IP addresses, positions) each get their own result, and that the same evidence again is answered from the cache with the JavaScript builder off.
  • pipeline/fiftyone_pipeline_cloudrequestengine/tests/test_cloudengine_cache.py: a cloud engine refuses a cache, and one given a cache anyway reads each request's response and stores nothing.
  • test_human_confidence.py: DerivedCloud refuses a cache, and one given a cache anyway gives each request the values its own response holds and stores nothing.

Local runs on Windows with Python 3.14, tests not marked live:

Package Result
fiftyone_pipeline_cloudrequestengine 202 passed
fiftyone_pipeline_cloudrequestengine/examples 116 passed, 4 skipped
fiftyone_pipeline_engines 171 passed
fiftyone_devicedetection_cloud 25 passed
fiftyone_ipintelligence_cloud 16 passed
location 14 passed
test_builder_cache.py in both examples packages 3 passed each

The other examples tests that failed locally need data files that CI's asset fetch provides and this checkout did not have (TAC-HashV41.hash, the evidence file, 51Degrees-LiteV41.ipi), so CI is the check for those.

Outstanding

  • No version change and no +semver line.
  • The live cloud tests need the CI keys, so CI is the check for them.

…oud Request Engine

A cloud engine accepts no evidence, so there is no key to use in a results
cache of its own, as the Cloud Aspect Engine specification says under
"Configuration options", where it recommends the cache goes on the Cloud
Request Engine instead.

- The cache setting of DeviceDetectionCloudPipelineBuilder,
  DeviceDetectionPipelineBuilder, IpIntelligenceCloudPipelineBuilder,
  IpIntelligencePipelineBuilder and LocationPipelineBuilder now adds the
  cache to the Cloud Request Engine, as .NET's cloud pipeline builders do.
  That engine keys the cache on the evidence it sends and applies its own
  cache rules, so a response made for one visitor is neither stored nor
  served, and a request that carries a session id, a sequence, JA4 or
  HTTP/2 settings, or a sealed result to redeem always goes to the cloud
  service. The on-premise branches are unchanged, because those engines
  already refuse a cache.
- CloudEngine.set_cache raises an exception that names the Cloud Request
  Engine, as the on-premise engines refuse a cache, and CloudEngine.process
  never uses a cache of the engine's own. DerivedCloud inherits both, so a
  redeemed Human Confidence result is never stored or served again.
- The builders' documentation says where the cache goes, and that with the
  JavaScript builder on every request carries a session id, which the Cloud
  Request Engine sends to the cloud service every time.

A caller that put a cache on a cloud engine directly now gets the
exception, and adds the cache to the Cloud Request Engine instead.

Tests, each failing on rc and passing here:
- test_builder_cache.py in fiftyone_devicedetection_cloud,
  fiftyone_ipintelligence_cloud and location, and in the two examples
  packages for the combined builders: the cache is on the Cloud Request
  Engine, two different requests give their own results, and the same
  evidence again is answered from the cache with the JavaScript builder off.
- test_cloudengine_cache.py: a cloud engine refuses a cache and reads each
  response whatever it holds.
- test_human_confidence.py: DerivedCloud refuses a cache, and one held
  anyway never serves a redeemed result.
@jwrosewell
jwrosewell merged commit 802efb1 into rc Dec 1, 2026
6 checks passed
@jwrosewell
jwrosewell deleted the fix/cloud-engine-cache-key branch December 1, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant