Skip to content

[FEATURE] ⚙️ Add options to change some string internals (used for cache keys + backplane channel) #448

@jodydonetti

Description

@jodydonetti

Problem

With some new and upcoming stuff (can't wait 🙂) something emerged: in some 3rd party distributed cache/backplane implementations there can be a series of special characters that are either not supported or have reserved, with a special meaning.

In the case of NATS we are talking about chars like "*", "!", "." and so on, which are reserved.

So what is emerging is the need to have the ability to change some of the internal strings used by FusionCache, both for cache keys and the backplane channel name.

Solution

I'll add some new options in the FusionCacheOptions type (so global per-cache instance, not per-key because it doesn't make sense) to allow changing the strings used internally by FusionCache: this will allow a clean result with some new integrations.

A note for 3rd parties

I think 3rd party implementers should anyway employ some sort of options to control how to deal with invalid/reserved characters, like in the case of NATS with "*", "!", "." and so on.

My personal idea for them is to offer an option like SpecialCharsHandlingMode or similar name, with 3 modes that come to mind:

  • Error: in case of undesired chars, throws a specific exception
    • PROS: any problematic char can be spotted immediately, and if used with o11y this can reduce the time to fix. Also, the input ends up in the distributed cache exactly as-is, debugging sessions are "transparent"
    • CONS: in case of undesired chars the normal flow will be broken
  • Normalize/Encode (default): in case of undesired chars, normalize them to something valid (eg: "*" -> "__star", etc). Not that it's strictly needed, but If this can be done in a bidirectional way it would be kinda like the encode/decode flow that happens with some chars in a url (eg: space char " " -> "%20" etc), but this is not mandatory
    • PROS: any problematic char can be automatically "fixed", so the normal flow will be never broken
    • CONS: the input does not necessarily end up in the distributed cache exactly as-is, so in some (not frequent) cases debugging sessions may be less "transparent". For example, the input is "ab:c" and in L2 ends up as "ab__colon__c" (or whatever). Finally, depending on the normalization scheme, there may be collisions (although reasonably rare) and the final normalized size will be slightly bigger
  • Base64 (or similar): the entire string (either cache key or channel) is converted to base64 or something like this, so that it doesn't matter the input, it will always be turned into something valid
    • PROS: any problematic char can be automatically "fixed", so the normal flow will be never broken
    • CONS: the input will never end up in the distributed cache exactly as-is, so debugging sessions will be harder and less "transparent". For example, the input is "ab:c" will become something like "TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcmsu" (or whatever). There will not collisions, but the final encoded size will be around 33% bigger

This is just some ideas I like to share, of course implementers can choose what they want.

A question can be: if 3rd parties will in fact implement some sort of transformation, why the need to customize the internal strings inside FusionCache? Because at least the "starting point" can be made as clear as possible, and in case a user will pick the Error mode (if so implemented) they can know what a mistake has been made on their side (where they have total control), and not on FusionCache (where they would not have total control).

Another thing is that even with the new options to configure the internal strings, although FusionCache can be configured TODAY with the right ones, in the future I may come up with newer ones, so AFTER a new release of FusionCache but BEFORE the new release of the 3rd party package problems may happen. Because of this, I think the default mode should be Normalize (or whatever name will be picked).

Something important though is that any transformation MUST remain internal to the 3rd party system only: in practice this means that when FusionCache asks a backplane implementation to send a notification for a key "foo/bar?*!", the backplane MUST send a notification for precisely that key so that other FusionCache instances receiving those notifications can reason about them and handle them correctly.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions