Skip to content

fix(Cache): delete hidden cache entries in the File handler - #10785

Open
gr8man wants to merge 1 commit into
codeigniter4:developfrom
gr8man:fix/cache-file-hidden-entries
Open

gr8man wants to merge 1 commit into
codeigniter4:developfrom
gr8man:fix/cache-file-hidden-entries

Conversation

@gr8man

@gr8man gr8man commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Description
Cache entries whose keys start with a dot were skipped by clean() / cache:clear, getCacheInfo() and deleteMatching(), so they could never be reported or removed through the framework API. This change makes those operations hidden-aware while keeping .htaccess protected from deleteMatching() and the htdocs protection files intact in clean(); regression tests and the user guide are updated. Follow-up to #10766.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

A cache key may begin with a period, so save() writes a hidden cache file.
clean() called delete_files() without $hidden, getCacheInfo() used a helper
that always skipped dot-leading names, and deleteMatching() used FNM_PERIOD.
Such an entry was not listed by getCacheInfo() nor bulk-removed by clean()
or deleteMatching(), so cache:clear left it in place permanently.

- clean(): pass $hidden = true. .htaccess, index.* and web.config stay
  protected by $htdocs.
- getCacheInfo(): add an optional $hidden parameter to get_dir_file_info(),
  keep its default behavior, and include hidden files.
- deleteMatching(): drop FNM_PERIOD so wildcards match dot-leading entries,
  and skip the .htaccess protection file case-insensitively.

The user guide and the 4.7.7 changelog describe the new behavior.
@carson-codeigniter4 carson-codeigniter4 Bot added needs template Opened issues not following the bug form template bug Verified issues on the current code behavior or pull requests that will fix them labels Nov 18, 2026
@carson-codeigniter4

This comment has been minimized.

@carson-codeigniter4 carson-codeigniter4 Bot removed the needs template Opened issues not following the bug form template label Nov 18, 2026

@michalsn michalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to keep the current behavior for the reasons I mentioned in my review: #10766 (review)

Applications can already use an explicit pattern like deleteMatching('.app_*') to remove files with that prefix. In 4.7.6, we deliberately preserved the glob() behavior where deleteMatching('*') skips files whose names start with a dot.

This PR would also make cache:clear delete unrelated files such as .gitkeep and .gitignore. Adding exceptions for those two names would still leave other hidden files in the cache directory subject to deletion.

@gr8man

gr8man commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

One concern with keeping the current behavior: without this change, cache entries whose keys start with a dot are never reported by getCacheInfo() and never removed by clean()/cache:clear or deleteMatching('*'). They can only be removed manually from the filesystem, making them effectively permanent cache entries — that is the bug this PR fixes.

Regarding .gitkeep/.gitignore: those are repository scaffolding files, not cache entries. Instead of reverting the whole change, could we protect them explicitly — i.e., add them to the protected list in delete_files() (alongside .htaccess, index.* and web.config) — so repository files stay safe while hidden cache keys can still be cleared? I'm happy to adjust the PR in that direction if you prefer.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants