zooniverse / json-api-client

Apache License 2.0
10 stars 5 forks source link

Cache hits for different requests can result in missing attribute on resources #33

Open camallen opened 8 years ago

camallen commented 8 years ago

Linked to: https://github.com/zooniverse/Panoptes-Front-End/issues/2921 Slightly related to: https://github.com/zooniverse/json-api-client/pull/31 (it caches based on full request params)

If i request a resource that allows attribute filtering in the serialized response it is cached via the type / id combo but may be missing expected attributes for the later cache hit use cases. The cache hit should really not occur as it's really a different request.

We should generate cache keys based on the request type and id + params, e.g. GET /api/projects/1 => "projects_c4ca4238a0b923820dcc509a6f75849b" GET /api/projects/1?cards=true => "projects_c41203d504194e2e6d818983d939ea74"

[1] pry(main)> Digest::MD5.hexdigest("1?cards=true")
=> "c41203d504194e2e6d818983d939ea74"
[2] pry(main)> Digest::MD5.hexdigest("1")
=> "c4ca4238a0b923820dcc509a6f75849b"

We will have to look at cache eviction (superagent-cache anyone?) here but at least we won't be returning possibly incorrect data depending on the order or request execution.