Skip to main content

Module legacy

Module legacy 

Source
Expand description

Reader for cache entries written by tower-http-cache 0.5.x.

Deprecated: this module and the legacy-bincode1-read feature that gates it are removed in 0.7.0. Cache entries are self-expiring, so once every 0.5.x-written entry has aged past its TTL plus its stale window the feature can be turned off. Disabling it is safe at any time; the only cost is a cold cache.

§Why this is hand-written

Calling bincode here would keep bincode 1.3.3 in the dependency graph and keep the permanently-ignored RUSTSEC-2025-0141 suppression in deny.toml, which is the thing 0.6.0 exists to clear. The bincode 1 default configuration is a small, fixed encoding, so the three struct shapes 0.5.x wrote are decoded directly:

  • fixed-width integers, little-endian;
  • every sequence, string and byte array prefixed with its length as a little-endian u64;
  • Option as a single u8 tag, 0 for None and 1 for Some.

§The shape

bincode1(RedisRecord { payload: bincode1(StoredEntry), expires_at_ms, stale_until_ms })

0.5.x’s Redis payload is a private StoredEntry with no tags field, so decode_legacy_redis sets tags: None unconditionally. Tags did not cross the 0.5.x Redis wire at all; asserting None is what pins the scope of that fix.

There was a second decoder here, for 0.5.x’s memcached record. It was removed along with the memcached backend itself in 0.6.0 – nothing can produce those bytes any more. See the CHANGELOG for why that backend never functioned; the decoder and its golden fixtures remain in git history at eb026cc should they ever be needed.

§Safety against hostile input

Every length read from the buffer is checked against the bytes remaining before it is used, so a corrupt u64 length cannot drive a large allocation, and no path can panic or read out of bounds. Both decoders also require the buffer to be consumed exactly.

Functions§

decode_legacy_redis
Decodes a 0.5.x Redis value: bincode1(RedisRecord).