Comments (25)
There is now a beta version of LazyCache 2.0 for netstandard 2 on nuget.org. Feedback most welcome.
dotnet add package LazyCache --version 2.0.0-beta01
In addition there are a set of dependency injection bindings available:
dotnet add package LazyCache.AspNetCore --version 2.0.0-beta01
from lazycache.
Hello Alastair
Would you still be interested in looking at my netstandard 2.0 implementation fork? I can't submit a pull request, since I'm not a contributor, but I've attached a Zip with my changes.
If you decide to roll this in, please let me know so I can point back to the "Offical" LazyCache nuget package
from lazycache.
I'll update the feed with the latest buildwhen I get home and see if that changes anything.
from lazycache.
well color me embarrassed! I was thinking of CachingService's GetOrAdd<T>
and just "assumed" MS did the same thing... helps if you RTFM.. thanks for catching that John.
from lazycache.
Yes, ASP.NET Core 2.0. Here's a DotNetFiddle of GetRelatedPosts.
This method is to fetch related posts and sort them based on match percentage for a blog API, but i'm not sure how this method would affect LazyCache. It just returns an IEnumerable of related posts.
I'm not confident in my C# code so if you see anything horrific, please let me know lol
from lazycache.
I seem to experience the same issue.
https://dotnetfiddle.net/Q6cqxs Code where I try to implement this.
Function: https://dotnetfiddle.net/B0hu7W
from lazycache.
Any movement on this? I would like to take advantage of this package in netstandard2.0 as well.
from lazycache.
Hi, thanks. I'm away for a couple of weeks bit I will review this on my return and try and pull it in. Thanks!
from lazycache.
I put up a MyGet Nuget feed with this alpha version until the official version can be released:
https://www.myget.org/F/lazycache/api/v3/index.json
from lazycache.
@GeekActual:
On line 65 of LazyCache/NetBridgeSpoof.cs, it should set the value of the cache item and return null if an existing value is not found. Otherwise, it won't work with .net standard 2.0:
public object AddOrGetExisting( string key , object value , CacheItemPolicy policy )
{
object result;
if (this.TryGetValue(key, out result)) {
return result;
}
else {
this.Set(key, value);
return null;
}
}
from lazycache.
@johnhamm:
are you sure about that return null? since it is a AddOrGetExisting, think you mean to have it as follows
public object AddOrGetExisting( string key , object value , CacheItemPolicy policy )
{
object result;
if (this.TryGetValue(key, out result)) {
return result;
}
else {
this.Set(key, value);
return value;
}
}
from lazycache.
Damn, didn't mean to close it.
from lazycache.
Yeah I also think it's odd that AddOrGetExisting returns null when an existing value isn't in the cache, but that's Microsoft's behavior so your NetBridgeSpoof class should as well so there aren't any side effects.
Besides, the CachingService checks to see if it is null when a new value is added, and returns the inserted value if that is the case:
https://github.com/jornj/LazyCache/blob/c1d8b105404b1483983778cffdf67282f560ca5f/LazyCache/CachingService.cs#L105
Microsoft's reference:
https://msdn.microsoft.com/en-us/library/dd988741(v=vs.110).aspx
"If the cache does not have a cache entry whose key matches the key parameter, a new cache entry is created, and the MemoryCache.AddOrGetExisting method overload returns null. If a matching cache entry exists, the existing entry is returned."
from lazycache.
Using the alpha package from @johnhamm's feed with .NET Core 2.0 and it appears as though caching isn't working. ObjectCache count isn't increasing and the lambda is being executed every time. Not sure what other information I can give you (relatively new to .net). Any ideas?
ConfigureServices:
services.AddScoped<CachingService>();
Controller:
result.RelatedPosts = _cachingService.GetOrAdd($"relatedPostsForPostId-{postId}", () => _postsRepository.GetRelatedPosts(post, relatedPostsPageLength).ToList());
from lazycache.
from lazycache.
Please let us know when you did, would love to try it out!
from lazycache.
OK I've created a fork and fixed the .NET core issues. You can find the myget link here:
https://github.com/johnhamm/LazyCache
from lazycache.
Updated but still it's not caching: https://i.imgur.com/CxJrObB.png
from lazycache.
All the unit tests passed. When I create a simple app.net core app, it caches. Can you upload a project?
from lazycache.
I just uploaded my project to github (was a bit lazy before not uploading it yet :D)
Here's the file that should do the caching.
https://github.com/Jeffroiscool/AnimeFlix/blob/master/AnimeFlix/Pages/Anime.cshtml.cs
from lazycache.
I am getting a cache entry when I try it on your project:
https://imgur.com/a/snSIm
from lazycache.
Strange, what did you change? Did you actually try it in the page model?
from lazycache.
Sorry for the lack of feedback, I had a smarter friend look for me and he made this commit to my program to get it working: Zeffuro/AnimeFlix@5bf02f7
And that's with using this version of Lazycache: https://www.myget.org/F/lazycache/api/v3/index.json
from lazycache.
I have started work on dotnet core, but have taken a slightly different approach to that of this fork. The basics are now working. I decided to target netstandard 2 (and not do multi targeting) and there are a number of breaking changes so this will be a major bump to version 2.0. Feel free to check out https://github.com/alastairtree/LazyCache/tree/feat/netcore2 if you are keen. Any feedback is welcome, and let me know if you think the breaking changes are unreasonable - I hope they should be very quick to fix.
If you are really keen the latests nupkg is available at https://ci.appveyor.com/project/alastairtree/lazycache/build/artifacts but I think it still needs some work so not a proper release yet.
from lazycache.
I expect to release version 2 soon (already out in pre release) and as no-one is shouting for a multi targeted net45/46 version I feel I can close this issue for the alternative fork. Please shout if you disagree.
from lazycache.
Related Issues (20)
- LazyCache.TryGetValue appears to return null value HOT 17
- Create a sectioned IAppCache
- how do I clean the cache items by wildcard of a key HOT 2
- Add TryGetValueAsync that evaluates GetValueFromAsyncLazy HOT 1
- Cache eviction policy when cache is full? HOT 1
- Absolute expiration does not work v2.4.0 HOT 1
- Implement MemoryCache.Trim() to allow explicit removal
- LongRunning shouldn't run more than once HOT 1
- About Cache availability mechanism HOT 2
- CachingService.TryGetValue returning wrong value HOT 2
- Cannot dispose of cache HOT 3
- How to create separate caches? Not seeing how this is done. HOT 1
- Do you have plans to upgrade to dotnet7 HOT 5
- Question/Proposal on the limit of Cache keying to strings vs. "TKey"
- Is it possible to have some kind of management console to show the list of keys and their expiry?
- Bug in Wiki: Why does the Cancellation Tokens example use two CancellationTokenSource?
- Singleton constraint conflict if IMemoryCache already exists
- Is it possible to set the maximum size limit of the LazyCache as is possible in IMemoryCache by MS? HOT 1
- PostEvictionCallBack causing memory leak
- Returning null still successfully adds entry
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 lazycache.