Skip to content

Allow null values pattern #301

Closed
Closed

Description

@fabionaspolini

Hi,

Sometimes the null value is a significative value and CacheManaget library does not support this case.
I would like manager this behavior.
My suggestion is enable/disable this feature by ICacheManager.Configuration.

Exemple:

cacheManager = CacheFactory.Build("name", settings => settings.WithMicrosoftMemoryCacheHandle("handle"));

// New property... default its false for compatibility
cacheManager.Configuration.AllowNull = true;

In my case, I read params from database and store in memory cache by X minute, but if value does not exists in database, I would like stored this key in memory cache with null value, and reduced sql overhead to try to obtain inexistent value.
This behavior is planned and supported by Microsoft IMemoryCache for example.

Activity

  1. MichaConrad commented on Dec 20, 2020

    @MichaConrad
    Collaborator

    Because of the architecture of CacheManager, storing null doesn't work.
    For memory caches only, yeah that would not be a problem.
    But, because CacheManager has to support distributed caching with serialization, just passing in null will be impossible to compute if the object cache is being used, because you cannot infer the real type if you just pass in null for an object.

    If I would redesign the library with a new API, I'd probably drop the object support and have only one non typed cache with a generic interface. And then, nulls could be supported.

    But no, for now that's by design.

  2. locked and limited conversation to collaborators on May 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions