Ask yourself these two questions regardless of the technology
consuming your API: "What do we define as frequently accessed data?"
"What do our consumers define as frequently accessed data?" Those
questions are a matter of judgment and engineering. What resources
should be in a cache, how long should they be in the cache, when
should we use temporal caches or spatial caches, do we prime our cache
or use demand caching and so on.
Possible caching architectures you could use...
Temporal cache is good when you can stamp the resources with a
"freshness" date - something like daily reporting data
Spatial cache is good when you use paging (like your example above)
and you're aware that your users generally drill in 2 or 3 pages deep
Priming cache is good when you know that the data will always be
requested - something like user information for login
Demand caching is good when you really don't know what data will be
used but you know it get's reused - something like products in a
catalog
Possible caching protocol implementation...
Given that the API is web based and depending on the types of
resources that you're wanting to expose (if they are optimistically
updated or not, or more immutable) then you can use Etags or entity
tags to drive caching behavior - keeping in mind there are different
types of caching that provide different functions.
Let's say your web app, ios app, android app and so on all need basic
information about the logged in user's organizations ( let's say you
have a multi-tenant SaaS model). Generally information about various
organizations do not change; they are often simi-static entities. So
you could implement something like:
1. The first user hits the API through web app requesting
"organizations/1" - the API returns the resource to the web app with
an Etag header => Etag: "12341234234214"
2. Now the web app (commonly referred to as the consumer or client
app) can choose to cache the resource with the Etag
3. Later a user from the same organization "logs in" to the consumer
app so the app makes a request to the API using the same organization
uri (organizations/1) and passes the "stored" Etag with the request
using an "If-none-match" http header (or others) - so something like
If-None-Match: "12341234234214" (side note, if you're dealing with
multiple resources you can pass in a comma delimited list of Etags
4. Here's where the HTTP magic happens: The API looks at the request
uri and checks the Etag, if it matches you send back a 304 Not
modified without a message body, if it does not match and the resource
has a different or no Etag associated to it then the response body
will be the resource with the new Etag.
As you can imagine this results in huge savings with interactions
between any client and the API: payload reduction, HTTP noise,
understood protocol (rfc2616), API work, API to data store work and I
am sure there is more.
Have a look @ rfc2616 on Etags:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.19
I hope that helps - I have found with the APIs I have had an
opportunity to work with and create... the closer I stick with chapter
5 of the Fielding dissertation (
http://www.ics.uci.edu/~fielding/pubs/
dissertation/rest_arch_style.htm) and rfc2616 (without going
overboard) the happier my consumers are because they can anticipate
the behaviors of my APIs.
Sorry if this is a bit much more information than you were looking
for, I love your question; sometimes, it seems, that caching / paging
is a last thought in APIs out in the wild.