Giter Club home page Giter Club logo

Comments (5)

rubaiyet-sadi avatar rubaiyet-sadi commented on May 26, 2024

Can I take this Issue?
Also how about moving Abstracting CaheItem as ICacheItem and both Serializarion.Json and Serialization.ProtoBuf-net projects can implement this

from cachemanager.

MichaCo avatar MichaCo commented on May 26, 2024

You mean JsonCacheItem.cs? CacheItem is already a base class in CacheManager.Core.
The JsonCacheItem is implementation specific, and should only be known to, for the Json serialization.
The protobuf-net version might need something similar but those items will never be shared with anything. So, no, there is no reason to abstract that I think.

Can I take this Issue?

Sure, go ahead and give it a try 😄

from cachemanager.

jzabroski avatar jzabroski commented on May 26, 2024

CacheItem is already a base class in CacheManager.Core

Sure, but it is not an interface, and the general question of why you need a base implementation is a good one.

Looking at the two current files:

They're nearly identical in terms of the properties they support.

Why not make the following ICacheItem interface:

public interface ICacheItem<TValue> {
        /// <summary>
        /// Gets the creation date of the cache item.
        /// </summary>
        /// <value>The creation date.</value>
        DateTime CreatedUtc { get; }

        /// <summary>
        /// Gets the expiration mode.
        /// </summary>
        /// <value>The expiration mode.</value>
        ExpirationMode ExpirationMode { get; }

        /// <summary>
        /// Gets the expiration timeout.
        /// </summary>
        /// <value>The expiration timeout.</value>
        TimeSpan ExpirationTimeout { get; }

        /// <summary>
        /// Gets the cache key.
        /// </summary>
        /// <value>The cache key.</value>
        string Key { get; }

        /// <summary>
        /// Gets or sets the last accessed date of the cache item.
        /// </summary>
        /// <value>The last accessed date.</value>
        DateTime LastAccessedUtc { get; set; }

        /// <summary>
        /// Gets the cache region.
        /// </summary>
        /// <value>The cache region.</value>
        string Region { get; }

        /// <summary>
        /// Gets the cache value.
        /// </summary>
        /// <value>The cache value.</value>
        TValue Value { get; }

        /// <summary>
        /// Gets the type of the cache value.
        /// <para>This might be used for serialization and deserialization.</para>
        /// </summary>
        /// <value>The type of the cache value.</value>
        Type ValueType { get; }
}

This then simplifies the implementation of Type ValueType { get; } since it will always be TValue.

More importantly, by creating a concrete contract for the Type of TValue, you can create a "key-value registry" wrapper around CacheManager to ensure type-safe access to read/write keys-value pairs.

from cachemanager.

MichaCo avatar MichaCo commented on May 26, 2024

The point is that CacheItem is the ONLY base element used in CacheManager's logic. It also has some special things implemented.
I don't want it to implement an interface and potentially expose the interface instead of the concrete class through the ICacheManager interface (e.g. GetCacheItem).
That's not how the thing should work. I explicitly prevent people from implementing their own CacheItem and then maybe introducing bugs by not implementing everything... In those cases it is much better to have a base class and if you need to customize it, you can extend it.

The Json Serializer version has similar properties, sure, but the usage and intention is totally different.
It will never be stored in cache and will never be used by the CacheManager logic; it is just used to transport the information and data. I needed it for the Json implementation, but I'm pretty sure there could also be other ways to implement it without such an object.

I'm not even sure if you would even need something like that for the Protobuf implementation

from cachemanager.

rubaiyet-sadi avatar rubaiyet-sadi commented on May 26, 2024

I agree with @MichaCo , I was thinking along the same lines as @jzabroski but then I realized for all the concrete implementation we have to decorate the attributes differently, so not much to gain on the specific implementations.

Another option is to inherit from a abstract class, but I think that would limit any specific CacheItem with no class inheritance.

from cachemanager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.