Skip to content

Conversation

@27Bslash6
Copy link
Contributor

Summary

  • Extend CacheKeyGenerator._normalize() with cross-language compatible type support
  • Add custom key= parameter escape hatch for complex types
  • Add comprehensive test coverage (67 new tests)

Supported Types

Type Normalization Cross-Language
Path .as_posix()
UUID str(uuid)
Decimal str(decimal)
Enum .value (recursive)
datetime .isoformat() (UTC only)
numpy.ndarray 1D, ≤100KB, i32/i64/f32/f64

Array Constraints (per security review)

  • 256-bit Blake2b hash - collision resistance at scale
  • Little-endian byte order - cross-platform determinism
  • 100KB per-array limit - memory safety
  • 5MB aggregate limit - DoS prevention
  • Version prefix __array_v1__ - protocol evolution

Rejected by Design

  • set/frozenset - mixed-type sorting crashes
  • pandas.DataFrame - Parquet serialization is non-deterministic

Escape Hatch

@cache(key=lambda arr: hashlib.blake2b(arr.tobytes()).hexdigest())
def process(arr: np.ndarray) -> float:
    return arr.mean()

Test plan

  • make quick-check passes
  • 53 key generator tests pass
  • 14 custom key function tests pass
  • CI passes

…and constrained numpy support

Add cross-language compatible type normalization to CacheKeyGenerator._normalize():

- Path/PurePath: .as_posix() for cross-platform consistency
- UUID: str(uuid) standard format
- Decimal: str(decimal) exact representation
- Enum: .value (recursive normalization)
- datetime: .isoformat() (UTC only, naive rejected)
- numpy.ndarray: 1D, ≤100KB, i32/i64/f32/f64 dtypes

Array constraints (per security review):
- 256-bit Blake2b hash (collision resistance)
- Little-endian byte order (cross-platform determinism)
- 100KB per-array limit, 5MB aggregate limit (DoS prevention)
- Version prefix __array_v1__ for protocol evolution

Add custom key= parameter escape hatch for complex types:
- 2D arrays, DataFrames, large data, custom objects
- Integrated in both sync and async wrapper paths

Rejected by design:
- set/frozenset (mixed-type sorting crashes)
- pandas.DataFrame (Parquet non-deterministic)
@27Bslash6 27Bslash6 force-pushed the feat/extended-key-generator-types branch from 31e106a to b56dfed Compare December 18, 2025 07:45
@codecov
Copy link

codecov bot commented Dec 18, 2025

Codecov Report

❌ Patch coverage is 27.90698% with 62 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/cachekit/key_generator.py 32.35% 37 Missing and 9 partials ⚠️
src/cachekit/decorators/wrapper.py 5.88% 11 Missing and 5 partials ⚠️

📢 Thoughts on this report? Let us know!

- Add TestKeyNormalization: long key shortening, special char replacement
- Add integration tests for custom key= parameter with L1-only mode
- Test custom key caching behavior, numpy array support, error handling
- Test async custom key function
- key_generator.py coverage: 93% → 96%
- wrapper.py coverage: 5% → 33%
@27Bslash6 27Bslash6 merged commit 78e025a into main Dec 18, 2025
36 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants