Overview of the Problem
When “cache not clearing” happens in ColdFusion, changes to templates, queries, or data don’t show up even after you attempt to flush caches via the ColdFusion Administrator or code. This typically means one or more caching layers is still serving stale content. Because ColdFusion supports several distinct cache types—template cache, object cache (EHCache), query cache, page cache (cfcache), ORM second-level cache—as well as external caches (browser, CDN, web server), clearing one cache might not affect others. Understanding which cache you’re fighting is the key to fixing the issue.
Why it happens:
- You’re clearing the wrong cache type.
- You’re on the wrong server/instance in a cluster or behind a load balancer.
- “Trusted Cache” is enabled and ColdFusion is using compiled templates from disk.
- The Disk Store for EHCache or page cache is not writable or is locked.
- External caches (browser/CDN/IIS/Apache) are still serving old content.
- Admin/API calls to clear caches silently fail due to permissions or Configuration.
Below is a comprehensive guide to diagnose and resolve this problem, along with preventative Best practices.
Possible Causes
- Template cache still in use due to Trusted Cache being enabled.
- Clearing the object cache (EHCache) but problem is actually query cache or page cache.
- Clearing a cache region with the wrong name or on the wrong instance.
- Multi-server/clustered Deployment where only one node is flushed.
- File-system permissions prevent ColdFusion from purging Disk Store or cfclasses.
- Browser/Proxy/CDN caching overrides origin changes.
- IIS/Apache output cache or Reverse proxy cache still valid.
- Long TTLs in cachePut/cachedWithin/cfcache keep stale data alive.
- Admin API method not executed with proper Authentication.
- Changes require a ColdFusion Service restart (e.g., after changing EHCache config).
Quick Cause/Solution map:
- Cause: Trusted Cache enabled with outdated compiled CFML. Solution: Disable Trusted Cache or explicitly clear template cache; if needed, delete cfclasses and restart CF.
- Cause: EHCache region not cleared. Solution: Use cacheClear(“region”) or Administrator “Cache Regions” to purge.
- Cause: Wrong node in a cluster. Solution: Clear caches on all nodes; call a cache-clearing endpoint on each server.
- Cause: Browser/CDN/IIS/Apache cache. Solution: Purge CDN/IIS/Apache caches; hard refresh; set Cache-Control headers.
- Cause: Permissions. Solution: Ensure the ColdFusion service account can write to Disk Store, cfclasses, and cache directories.
Step-by-Step Troubleshooting Guide
Step 1: Identify which “cache” you actually need to clear
- Template cache (compiled CFML): Affects .cfm/.cfc changes not appearing.
- Object cache (EHCache): Affects cachePut/cacheGet or region-based caches.
- Query cache (cfquery cachedWithin/cachedAfter): Affects stale query result sets.
- Page cache (
): Affects entire page output caching to disk. - ORM second-level cache: Affects stale entity data from Hibernate.
- External caches (browser/CDN/IIS/Apache): Affects static assets and dynamic responses.
Tip: Change a page to print a unique timestamp. If the timestamp doesn’t change after a “clear,” you’re still seeing cached output.
Step 2: Verify ColdFusion Administrator cache operations
-
Template cache:
- ColdFusion Administrator > Caching
- Click “Clear Template Cache Now.”
- If Trusted Cache is enabled, consider temporarily disabling it or performing a full clear after Deployment.
-
Query cache:
- ColdFusion Administrator > Caching
- Click “Clear Query Cache Now.”
-
Object cache (EHCache):
- ColdFusion Administrator > Caching > Cache Regions
- Clear specific regions or all regions. Verify region names.
-
Page cache (cfcache):
- ColdFusion Administrator > Caching
- Locate page cache settings/directory and purge it.
Note: On locked-down servers, these buttons may fail silently if the CF service user lacks write permissions. Check logs to confirm success.
Step 3: Clear caches programmatically (application-level)
- EHCache regions:
- Clear a region or all cached items.
CFScript:
cfml
// Clear the default region
cacheClear();
// Clear a specific region
if (cacheRegionExists(“users”)) {
cacheClear(“users”);
}
// Remove a specific key
cacheRemove(“user:123”, “users”);
- Put values with sensible TTL to avoid stubborn staleness:
cfml
cachePut(
id = “user:#userId#”,
value = userData,
timespan = createTimespan(0,0,30,0), // 30 minutes
region = “users”
);
-
ORM cache:
cfml
// Reload mappings and clear second-level cache
ormReload();
// Consider transactional flush/clear for session cache issues
ormFlush(); -
Page cache (
): - Programmatically delete cached files if you’re using a file-based page cache directory (ensure you target the correct path and have permissions).
- Alternatively, adjust cfcache timespan or key strategies.
-
Query cache:
- Queries cached via cachedWithin/cachedAfter are purged through the Administrator or by waiting for TTL to expire. Consider reducing TTL during development to avoid confusion.
Step 4: Template cache considerations (Trusted Cache and cfclasses)
- If Trusted Cache is enabled, ColdFusion does not check source timestamps; it serves compiled templates from the cfclasses directory.
- If clearing via the Administrator doesn’t work:
- Stop the ColdFusion service.
- Delete the contents of the cfclasses directory for the instance.
- Typical location resembles: [cf_instance]/cfclasses
- Example: [ColdFusionRoot]/cfusion/cfclasses (varies by installation and instance name)
- Start the ColdFusion service.
Caution: Only delete files inside cfclasses; CF will recompile on demand.
Step 5: Multi-instance and clustered environments
- Confirm which instance you’re logged into in the Administrator; each instance has its own caches.
- For clusters behind a load balancer, clear caches on all nodes.
- Ensure session affinity (“sticky sessions”) isn’t masking which node you’re interacting with.
- Consider a shared cache invalidation endpoint:
- Expose a secure URL on each node that runs cacheClear() and invoke it on every node during deployments.
Step 6: External caches (browser/CDN/IIS/Apache)
- Browser:
- Use hard refresh or append a cache-busting query parameter, e.g., /app.css?v=20240913.
- Set response headers for dynamic pages:
- Cache-Control: no-store, no-cache, must-revalidate
- Pragma: no-cache
CFML example:
cfml
cfheader(name=”Cache-Control”, value=”no-store, no-cache, must-revalidate, max-age=0″);
cfheader(name=”Pragma”, value=”no-cache”);
cfheader(name=”Expires”, value=”0″);
-
CDN (e.g., Cloudflare/Akamai/Fastly):
- Purge by URL, by tag, or full purge as appropriate.
- Reduce edge TTL for dynamic pages.
-
IIS/Apache:
- IIS Output Caching: Disable or clear entries for affected URLs.
- Apache mod_cache/proxy caches: Purge or disable for dynamic routes; check rewrite rules.
Step 7: Permissions and Disk Store issues
- Ensure the ColdFusion service account has write permissions to:
- EHCache Disk Store directory configured in Administrator.
- Page cache directory (if using cfcache).
- cfclasses directory (compiled CFML).
- If EHCache Disk Store is set to a path that doesn’t exist or is read-only, clears may fail silently and stale disk entries remain. Fix the path or permissions and restart ColdFusion.
Step 8: Validate the result
- Update a page to print a changing token (timestamp or build number).
- Inspect ColdFusion logs for cache clear events (see Diagnostics below).
- If changes still don’t show:
- Re-check you targeted the correct cache type.
- Repeat on every node in the cluster.
- Temporarily disable Trusted Cache and retest.
- Restart ColdFusion as a last resort after confirming all above.
Diagnostics and Verification
Logs to check
- application.log or coldfusion-out.log typically records administrator actions and errors. Look for entries confirming clears and any permission errors.
Example log lines:
Information [admin] Template cache cleared by user ‘admin’.
Information [admin] Cleared query cache.
Warning [cache] Failed to purge EHCache Disk Store at D:\cf\cache\ehcache: Access denied.
- If no entries appear after clicking clear buttons, the action may not have executed or you’re on a different instance than expected.
Programmatic verification
-
EHCache:
cfml
writeOutput(“Users region count: ” & cacheCount(“users”));
writeDump(var=cacheGetAllIds(“users”), label=”Keys in users region”); -
Template changes:
- Print a build/version variable from Application.cfc and confirm it changes after deployment.
-
HTTP headers:
- Use curl or browser devtools to verify Cache-Control and Expires headers.
Example:
curl -I https://example.com/somepage.cfm
Check for:
Cache-Control: no-store, no-cache, must-revalidate, max-age=0
Common mistakes and How to Avoid Them
- Clearing object cache when the issue is template cache: Verify what changed—code vs data—and clear accordingly.
- Forgetting multi-node purges: Always purge all nodes in a cluster.
- Using Trusted Cache in development: Disable Trusted Cache while developing; enable only for production with proper deployment scripts.
- Mis-typed region names: Use cacheRegionExists() and Administrator “Cache Regions” to verify names.
- Skipping permissions checks: Ensure CF’s service account can write to Disk Store, cfclasses, and cache directories.
- Over-relying on browser refresh: Always confirm with server-side logs or timestamped content.
- Long TTLs in page or object caches: Use conservative TTLs on dynamic routes and build cache keys that change with inputs.
Best practices (Prevention Tips)
-
Deployment hygiene:
- If Trusted Cache is enabled, automatically clear template cache on each node right after deployment.
- Consider deleting cfclasses during deployments, followed by a warm-up step to recompile key pages.
-
Centralized cache invalidation:
- Implement a secure cache-clear endpoint that:
- Clears template cache (if applicable).
- Clears relevant EHCache regions.
- Purges query/page cache if used.
- Orchestrate calls to every node during deployment.
- Implement a secure cache-clear endpoint that:
-
Cache design:
- Use shorter TTLs for highly Dynamic content.
- Namespace cache keys (e.g., “product:v2:123”) to allow versioned invalidation.
- Separate cache regions per domain area (users, products, settings).
-
Environment parity:
- Disable Trusted Cache in dev/test to reduce confusion.
- Keep caching configurations consistent across nodes.
-
Observability:
- Log cache clear actions explicitly in your deployment tooling.
- Add an endpoint to report cache sizes/keys for quick verification in non-prod.
-
External cache alignment:
- Coordinate CDN and web server cache rules with application cache strategy.
- Emit explicit Cache-Control headers for dynamic resources.
Key Takeaways / Summary Points
- “Cache not clearing” usually means you’re clearing the wrong cache or the wrong node.
- Identify the cache type (template, object, query, page, ORM) before clearing.
- Trusted Cache and compiled templates often cause surprises; clear template cache or cfclasses as needed.
- In clustered setups, purge all nodes and any external caches (browser/CDN/IIS/Apache).
- Verify success using logs and programmatic checks (e.g., cacheCount, timestamps).
- Enforce permissions and automate cache invalidation during deployments.
FAQ
How do I clear the template cache without using the Administrator UI?
- If you can’t use the UI, stop the ColdFusion service, delete the contents of the instance’s cfclasses directory, and start the service again. You can also expose a secure admin-only endpoint that triggers the relevant clear actions if your org allows it.
Why do changes appear on one server but not the other?
- You’re likely behind a load balancer with multiple ColdFusion nodes. Clear caches on all nodes, ensure sticky sessions aren’t masking your tests, and consider a coordinated cache-clear step in your deployment pipeline.
Does clearing EHCache affect queries cached with cfquery cachedWithin?
- No. Query cache is separate from EHCache object cache. Use the ColdFusion Administrator “Clear Query Cache” or reduce query cache TTL. If needed, temporarily disable query caching during Debugging.
My cfcache pages ignore my code updates. What should I check?
- Confirm the page cache directory and TTL for cfcache. Purge the page cache directory, ensure CF can write to it, and confirm no external cache (CDN/IIS/Apache) is serving stale responses. Consider cache-busting or disabling page cache on dynamic routes.
After I clear caches, I still see old CSS/JS. What’s wrong?
- That’s usually a browser or CDN cache. Add cache-busting query params to static assets (e.g., app.css?v=build123), adjust Cache-Control headers, and purge your CDN.
