Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimeSpan cannot be used for caching. #9612

Closed
Nokecy opened this issue Jul 17, 2021 · 2 comments
Closed

TimeSpan cannot be used for caching. #9612

Nokecy opened this issue Jul 17, 2021 · 2 comments

Comments

@Nokecy
Copy link
Contributor

Nokecy commented Jul 17, 2021

   public class CacheItem
    {
        public TimeSpan TimeSpan { get; set;}
    }

  [Fact]
        public async Task Test_CacheAsync()
        {
            var cache = GetService<IDistributedCache<CacheItem, string>>();

            var cacheValue = new TimeSpan(10, 10, 10);
            
            await cache.SetAsync("abc", new CacheItem() { TimeSpan = cacheValue });

            var value = await cache.GetAsync("abc");

            value.TimeSpan.ShouldBe(cacheValue);
        }

Use memory cache
The test is Failed

@maliming maliming self-assigned this Jul 18, 2021
@maliming maliming added this to the 4.4-final milestone Jul 18, 2021
@maliming maliming changed the title TimeSpan cannot be used for caching。v4.3 TimeSpan cannot be used for caching. Jul 18, 2021
@maliming
Copy link
Member

maliming commented Jul 19, 2021

hi

You can implement a converter, See: dotnet/runtime#29932 (comment) dotnet/runtime#54186

It will be available in net 6.

@maliming maliming removed this from the 4.4-final milestone Jul 19, 2021
@maliming maliming removed their assignment Jul 19, 2021
@Nokecy
Copy link
Contributor Author

Nokecy commented Jul 19, 2021

@maliming thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants