Comments (5)
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.
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.
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:
- https://github.com/MichaCo/CacheManager/blob/dev/src/CacheManager.Serialization.Json/JsonCacheItem.cs#L6
- https://github.com/MichaCo/CacheManager/blob/dev/src/CacheManager.Core/CacheItem.cs
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.
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.
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)
- Json serializer does not support on redis? HOT 1
- Is it possible to do cache eviction when backplane is down HOT 1
- Cache manager locking threads HOT 2
- .Get() after .Add() or .AddOrUpdate fetches from Redis unexpectedly when using inProcessCache HOT 2
- Supporting .NET Standard 2.1 HOT 1
- Is CacheManager a dead project? HOT 1
- CacheManager.StackExchange.Redis add list type data problem
- How to get all the following data according to the prefix of the key
- Ocelot Cache - How do we Cache only success(200) response from micro services via API Gateway HOT 1
- Is there a plan to release a stable 2.x version ? HOT 1
- [Question] Using redis both for cache and for signalR HOT 1
- Changes in the object reflect in Cache without updating HOT 2
- Not possible to flush whole cache when using in-memory and redis handles HOT 2
- How to run AspnetCore.WebApp for NET 5.0? HOT 1
- Can we override config expiration settings during Add()? HOT 2
- Is this project still supported? HOT 3
- How to use SQL Server? HOT 1
- [Question] synchronize cache layer on application startup HOT 1
- New version / Nuget packages HOT 8
- How to 'add' item to all layers very first time HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cachemanager.