Cache and limit direct access to the data managed on your Directus instance, powered by Cloudflare Workers, Workers KV and Cloudflare Pages.
MIT License
Cache and limit direct access to the data managed on your Directus instance, powered by Cloudflare Workers, Workers KV and Cloudflare Pages.
Head over to the Directus instance at https://cztkclnq.directus.app.
Login with the following credentials.
[email protected]
abcd1234
Create > update > delete your content.
Permissions have been set to prevent changes to certain items.
Check out your updates at https://directus-cf-cache.pages.dev.
Fetching and storing content into Workers KV.
Serve requests either from the origin or the KV cache.
Store cached content retrieved from Directus.
Host the demo Vue 3 web application.
Create a Fork of this GitHub repository as the deployments are pushed via GitHub Actions.
articles
, projects
and people
.cf_cache_options
global_query_params
global_query_params
:
description
with string
typeoperation
with string
type (either list
or get
)collection
with string
type (collection names that you want to cache)key
with string
type (cache key to differentiate between presets)enabled
with boolean
query_params
with json
(the query that will be sent with the request)file_paths
with csv
(the paths containing files from the result)sort
with integer
to be used for sortingcf_cache_options
:
cache_mode
with string
(origin_priority
,cache_priority
,origin_only
,cache_only
)preset_requests
with One to Many Relationship
on global_query_params
with a foreign key of cf_cache_option
.Relationship
and set the sort field as sort
to enable sorting.global_query_params
.Secret
with your secret and copy this value somewhere.Cf Cache Options
App Access
.All Access
for Read
column of the tables you wish to cache including cf_cache_options
Demo
cf_cache_options
configurationDemo
preset_requests
configuration
directus-cf-cache
in your GitHub account.dist
.app
.VITE_DIRECTUS_CF_CACHE_URL
with your Cloudflare Worker URL such as https://directus-cf-cache.<your workers subdomain>.workers.dev
.Open the forked GitHub project > Settings > Secrets.
Create the following repository secrets:
You may refer to .env.sample for sample values.
CLOUDFLARE_ACCOUNTID
with the Account ID.CLOUDFLARE_PAGES_WEBHOOK_URL
with the Deploy hook URL.CLOUDFLARE_TOKEN
with the API Key.CLOUDFLARE_ZONEID
with the Zone ID, empty string unless you are using a custom domain.DIRECTUS_ACCESS_TOKEN
with the token.DIRECTUS_CF_CACHE_KV
with the Namespace ID.DIRECTUS_SERVER_URL
with the root URL of your Directus instance.DIRECTUS_WEBHOOK_SECRET
with the secret.WORKER_ROUTES
with your custom domain or the workers.dev route.Click on the Actions tab, manually run the workflows.
list
results to handle bigger datasetsDeveloped by licitdev
[^1]: Changes may take up to 60 seconds to propagate globally when the request is served from the KV cache instead of the origin https://developers.cloudflare.com/workers/learning/how-kv-works