Skip to content

Workers cache purge call results in error when run in local dev mode #15183

Description

@Shotster

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.

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')"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Status
    Untriaged

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions