cloudflare / cloudflare/workers-sdk
Workers cache purge call results in error when run in local dev mode
- Dominant language
- TypeScript
- Stars
- 4.5k
- Forks
- 1.5k
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 186
Description
### What versions & operating system are you using?
Wangler v4.123.0 on Intel Mac running Sequoia 15.7.3
### Please provide a link to a minimal reproduction
replicated from example in blog post https://blog.cloudflare.com/workers-cache/#a-cache-between-every-worker-entrypoint
### Describe the Bug
Either of the following work when deployed to `workers.dev` but error out when run in dev mode locally.
```javascript
import { cache, WorkerEntrypoint } from "cloudflare:workers";
export class CachedEntrypoint extends WorkerEntrypoint {
async fetch( request ) {
// works fine
}
async invalidate1( pathToPurge ) {
const result = await this.ctx.cache.purge( { // Fails with "Cannot read properties of undefined (reading 'purge')"
pathPrefixes : [ pathToPurge ],
} )
}
async invalidate( pathToPurge ) {
const result = await cache.purge( { // Fails with "cache.purge is not a function"
pathPrefixes : [ pathToPurge ],
} )
}
}
```
### Please provide any relevant error logs
`"status":500,"message":"cache.purge is not a function"`
`"status":500,"message":"Cannot read properties of undefined (reading 'purge')"`
Contributor guide
Research direction
Reproduce the blog example locally using CachedEntrypoint.invalidate1 and invalidate, focusing on the two cloudflare:workers cache.purge calls shown in the issue. Trace how local development handles these APIs and verify that both calls work locally without either reported error, matching deployed workers.dev behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- cli, devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 62/100