Skip to content

Dependency keys not unescaped when reading from Redis cache #4

@gfraiteur

Description

@gfraiteur

Summary

Dependency keys are escaped when stored but never unescaped when read back, causing dependencies to be returned with escaped characters instead of the original values.

Root Cause

In RedisCachingBackend.cs, the GetShortKeyFromUserKey method escapes special characters:

return new ShortKey( userKey.Replace( "{", "%7B" ).Replace( "}", "%7D" ).Replace( ":", "%3A" ) );

However, there is no corresponding GetUserKeyFromShortKey method to unescape these characters when reading dependencies back from Redis.

Symptoms

When a cache item has dependencies containing {, }, or : characters:

  • The dependencies are stored correctly with escaped values
  • When reading the item back, the dependencies array contains the escaped values (%7B, %7D, %3A) instead of the original characters ({, }, :)

Suggested Fix

Add a GetUserKeyFromShortKey method to unescape the keys:

private static string GetUserKeyFromShortKey( ShortKey shortKey )
{
    return shortKey.Key
        .Replace( "%7B", "{" )
        .Replace( "%7D", "}" )
        .Replace( "%3A", ":" );
}

And call it when converting forward dependencies back to user keys in GetItemAsyncCore or similar methods.

Affected Code

  • PostSharp.Patterns.Caching.Backends.Redis/RedisCachingBackend.cs
  • PostSharp.Patterns.Caching.Backends.Redis/DependenciesRedisCachingBackend.cs

Filed by Claude

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions