Giter Site home page Giter Site logo

Comments (25)

alastairtree avatar alastairtree commented on May 30, 2024 3

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.

matthewacme avatar matthewacme commented on May 30, 2024 2

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

LazyCache.zip

from lazycache.

johnhamm avatar johnhamm commented on May 30, 2024 2

I'll update the feed with the latest buildwhen I get home and see if that changes anything.

from lazycache.

matthewacme avatar matthewacme commented on May 30, 2024 1

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.

bradley-varol avatar bradley-varol commented on May 30, 2024 1

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.

Zeffuro avatar Zeffuro commented on May 30, 2024 1

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.

bhedia avatar bhedia commented on May 30, 2024 1

Any movement on this? I would like to take advantage of this package in netstandard2.0 as well.

from lazycache.

alastairtree avatar alastairtree commented on May 30, 2024

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.

johnhamm avatar johnhamm commented on May 30, 2024

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.

johnhamm avatar johnhamm commented on May 30, 2024

@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.

matthewacme avatar matthewacme commented on May 30, 2024

@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.

matthewacme avatar matthewacme commented on May 30, 2024

Damn, didn't mean to close it.

from lazycache.

johnhamm avatar johnhamm commented on May 30, 2024

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.

bradley-varol avatar bradley-varol commented on May 30, 2024

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.

matthewacme avatar matthewacme commented on May 30, 2024

from lazycache.

Zeffuro avatar Zeffuro commented on May 30, 2024

Please let us know when you did, would love to try it out!

from lazycache.

johnhamm avatar johnhamm commented on May 30, 2024

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.

Zeffuro avatar Zeffuro commented on May 30, 2024

Updated but still it's not caching: https://i.imgur.com/CxJrObB.png

from lazycache.

johnhamm avatar johnhamm commented on May 30, 2024

All the unit tests passed. When I create a simple app.net core app, it caches. Can you upload a project?

from lazycache.

Zeffuro avatar Zeffuro commented on May 30, 2024

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.

johnhamm avatar johnhamm commented on May 30, 2024

I am getting a cache entry when I try it on your project:
https://imgur.com/a/snSIm

from lazycache.

Zeffuro avatar Zeffuro commented on May 30, 2024

Strange, what did you change? Did you actually try it in the page model?

from lazycache.

Zeffuro avatar Zeffuro commented on May 30, 2024

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.

alastairtree avatar alastairtree commented on May 30, 2024

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.

alastairtree avatar alastairtree commented on May 30, 2024

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)

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.