Roblox Requests

Caching Responses

How to cache responses from static data sources.

Roblox Requests

When/why should I cache?

Many CDNs automatically cache their responses for you. Local caching, however, will reduce ratelimit and network usage by using locally stored responses.

You should only cache responses from sources that will always give you the same content. Don’t cache any API endpoints that return different data when using the same request options (query string, body, etc.)

Cache Patterns

In order to enable caching, we have to mark certain URLs as safe to cache. To do this, we use URL patterns.

Example patterns:

URL patterns use the asterisk (*) as a wildcard that allows any data. This allows you to cache a large range of URLs.

Special Cases

If you provide a domain name such as "" with no trailing slash, it will be assumed that you want to cache every URL on GitHub. However, using "" will only cache the front page for GitHub.

Passing "*" to include subdomains will implicitly include "".

Setting up Cache

To set up caching for a URL, we’ll use the http.cache object. Here, we set up the cache to store every "" URL:


We can also pass multiple URLs in one call:

http.cache.cache_locally({"", ""})

To check if a response was accessed from the cache, use the Response.from_cache attribute:


-- false

-- true, using initial response that was cached

Cache Expiry

If you have data that you only want to store for a certain amount of time, you can set an expiry:

http.cache.cache_locally("", {
    expires = 5*60  -- expire after 5 minutes

If the cached response is more than 5 minutes old, it will send a new request and replace the old one.

Global Caching

Requests also supports global caching, backed by Data Stores and MessagingService. This is only recommended if your game is accessing very large static resources. To enable global caching for a set of URLs, just use the cache_globally function:


-- with expiry
http.cache.cache_globally("", {expires=60})

Global caching works by keeping an index of cached URLs in each server that is updated in realtime via MessagingService. This way, Requests knows if a URL is cached without having to check the Data Store. If a response is cached, it downloads it from the Data Store instead of the actual server.