Why cache locally?
Three reasons to keep a local copy of Stora data:- Rate limits — The API allows 10 requests per second and 60 per minute. A booking flow that fetches sites, unit types, prices, products, protection levels, and coupons on every page load will burn through that budget fast.
- Latency — Serving cached data from your own database avoids multiple Stora API round trips per request.
- Resilience — If the Stora API is temporarily unreachable, your integration can continue to serve cached data rather than failing entirely.
What to cache
Not all resources change at the same rate. Grouping them by how often they change helps you decide what to cache and how aggressively.Tier 1: near-static resources
These represent the physical and commercial structure of a storage business. They change rarely — typically only when an operator reconfigures their offering.
Cache these aggressively. They’re ideal candidates for a long-lived local cache that’s only invalidated when you receive a webhook or detect a change via polling.
Tier 2: business-event driven
These change when an operator takes a deliberate action — updating pricing, creating a promotion, or adjusting protection options. Changes are infrequent but meaningful.
Cache these and invalidate on webhooks. When you receive a
unit_type.updated, coupon.updated, or protection_level.updated event, re-fetch the affected resource to pick up the new data.
Price changes on unit types and protection levels trigger their respective
.updated webhooks. Use these to keep cached pricing current, including Unit Type live_prices used by booking flows.Tier 3: transactional
These change with customer and operational activity — bookings, payments, status changes. They update frequently and are often specific to a single transaction.
Cache selectively based on your use case. You probably don’t need a full local copy of every invoice — but if you’re building a dashboard that shows unit occupancy across sites, caching unit status and keeping it fresh via webhooks makes sense.
Architecture
A typical caching architecture has three components:- Local data store — A database or cache that holds copies of Stora resources. This is what your application reads from.
- Sync worker — A background process that receives webhooks, fetches fresh data from the API, and updates your local store.
- Your application — Reads exclusively from the local store, never directly from the Stora API during user-facing requests.
Syncing multiple operators
Partner apps and developers managing several operator accounts must keep sync state separate for each connected operator. Associate snapshots, page progress, polling checkpoints, local resource mappings, and queued work with that operator connection. Never let a checkpoint or currently selected token from one operator control another operator’s sync. Run an initial sync for each newly connected operator. Reuse a previous checkpoint only for the same operator when you have a trustworthy, completed checkpoint and its corresponding local data. Otherwise, repeat the snapshot and reconciliation procedure below. Use the verified webhook connection context when queueing work and choosing credentials.Initial sync
Register your webhook endpoint and durably retain incoming events before you fetch the initial data. Record the sync-start timestamp for each resource type, then paginate through the resources you want to cache. Buffer events until the snapshot is stored so a snapshot write cannot overwrite a newer event update.next is null.
After storing the snapshot, reconcile buffered events by re-fetching each affected resource. Webhook delivery order is not guaranteed, so do not overwrite current data with older payloads. Serialise updates per resource so concurrent fetches cannot overwrite newer results. Retry failed reconciliation work.
For resources with time-range filters, run a catch-up poll from just before the recorded sync-start timestamp. See Polling with updated_after for checkpoint handling. Continue retaining events during reconciliation, then process them as they arrive. Schedule periodic reconciliation to recover changes missed during delivery failures.
Working within rate limits
With a limit of 60 requests per minute, a full initial sync takes time — especially for operators with large inventories. Some practical tips:- Prioritise by tier. Sync near-static resources (Tier 1) first, since they’re the most widely needed and least likely to change mid-sync.
- Pace your requests. Apply limits per operator, not per token or across your entire service. Stay below each operator’s rate limit to leave headroom for its other API activity.
- Run during quiet periods. If possible, run your initial sync outside business hours when other API usage is low.
- Track progress. Record the last page you successfully synced so you can resume if the process is interrupted.
Keeping your cache fresh with webhooks
Once your initial sync is complete, webhooks are the primary mechanism for keeping your cache up to date. When a resource changes in Stora, a webhook event is sent to your endpoint — your sync worker receives it and re-fetches the affected resource.The pattern
1
Receive the webhook event
Your endpoint receives a
POST request with the event payload. Verify the signature and durably enqueue the event before returning 2xx. If enqueueing fails, return a non-2xx response so Stora can retry.2
Identify the affected resource
In a background worker, use
event.type to determine what changed and event.data to identify the resource.3
Update your local store
Re-fetch the resource and upsert it in your local store. Serialise updates per resource to prevent concurrent writes from applying older results. You can use the event payload directly if you reject stale updates. Retry worker failures from your queue because Stora does not retry acknowledged deliveries.
Which events to subscribe to
Subscribe to the events that match the resources you’re caching. Here’s a mapping of resources to their relevant webhook events:Some resources — sites, products, product categories, contract templates, and staff — don’t have webhook events yet. For these, rely on polling with
updated_after as described in the next section.Using the event payload directly
Webhook payloads include the full resource inevent.data. You can update your local store from the payload if you prevent older events from overwriting newer data. Otherwise, use the event to trigger a re-fetch.
expand parameter instead.
Catching up on missed updates
Stora makes up to six delivery attempts, including the initial attempt. The five retry delays total approximately 20 hours 35 minutes, excluding request duration and job scheduling. Use polling to recover after retries are exhausted and to refresh resources without webhook events.Polling with updated_after
The updated_after filter lets you fetch only resources that have changed since a given timestamp. This is the primary mechanism for:
- Recovering from missed webhooks — after extended downtime, resume polling each resource type from its last completed polling checkpoint, with an overlap.
- Syncing resources without webhooks — for resources like sites, products, and staff that don’t emit webhook events, periodic polling is the only option.
- Record the poll-start timestamp before requesting the first page.
- Set
updated_afterto a time before the previous completed polling checkpoint. Choose an overlap that accounts for timestamp precision and clock differences. - Use the same filter values for every page. You can set
updated_beforeto the poll-start timestamp to bound the range. - Fetch and apply every page. Upsert by resource ID and prevent older results from overwriting newer data.
- Save the poll-start timestamp as the new checkpoint only after all pages and local writes succeed. If the poll fails, keep the previous checkpoint and retry.
Recommended polling intervals
Polling is a fallback, not a primary strategy. Use conservative intervals that respect rate limits:Combining webhooks and polling
The most robust approach uses both strategies together:- Webhooks handle the common case — near real-time updates for resources that support them.
- Polling handles the edges — resources without webhooks, recovery after downtime, and a safety net against missed events.