Skip to content

fix(memory): match clear_pattern case-sensitively on every platform - #204

Merged
allen0099 merged 1 commit into
masterfrom
fix/memory-fnmatchcase
Sep 26, 2026
Merged

allen0099 merged 1 commit into
masterfrom
fix/memory-fnmatchcase

Conversation

@allen0099

@allen0099 allen0099 commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

Closes #179

Summary

  • MemoryBackend.clear_pattern() now uses fnmatch.fnmatchcase. fnmatch.fnmatch passes both arguments through os.path.normcase, which lowercases on Windows, so cache:user:* also cleared cache:User:1 there. Redis is case-sensitive everywhere.
  • Document in docs/BACKENDS.md (and zh-TW) where the memory glob syntax still differs from Redis.
  • CHANGELOG Fixed entry.

Glob differences, checked against a live Redis

Pattern Memory Redis
a[*]b a*b a*b
a\*b a\b (backslash is literal) a*b
a[!x]b anything but x a!b, axb
a[^x]b a^b, axb anything but x
a?b same same

So the docs recommend bracket escapes, and note that negation is [!...] on memory and [^...] on Redis. Making memory accept Redis syntax would change the meaning of existing patterns, so it is left out of this fix.

Tests

  • test_memory_backend_clear_pattern_is_case_sensitive_on_windows swaps os.path.normcase for ntpath.normcase. With the fix stashed, it is the only test that fails.
  • ruff, mypy --strict, and the full suite against live Redis and Memcached (CACHEX_REQUIRE_LIVE_SERVERS=1): 858 passed.

fnmatch.fnmatch runs both arguments through os.path.normcase, which
lowercases on Windows, so cache:user:* also cleared cache:User:1 there.
Redis matches case-sensitively everywhere. Use fnmatch.fnmatchcase.

Document the two places where the memory glob syntax still differs from
Redis: [!...] negation and bracket escapes instead of backslashes.

Closes #179
@allen0099 allen0099 added this to the 0.3.8 milestone Sep 26, 2026
@allen0099 allen0099 added bug Something isn't working backends Cache backends and their atomic primitives labels Sep 26, 2026
@allen0099
allen0099 merged commit c8769eb into master Sep 26, 2026
11 checks passed
@allen0099
allen0099 deleted the fix/memory-fnmatchcase branch September 26, 2026 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backends Cache backends and their atomic primitives bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MemoryBackend: match patterns with fnmatchcase

1 participant