cake-build / cake

:cake: Cake (C# Make) is a cross platform build automation system.
https://cakebuild.net
MIT License
3.91k stars 730 forks source link

Cake caches the response of package versions for 30 minutes. #2338

Open robolize opened 6 years ago

robolize commented 6 years ago

What You Are Seeing?

Not able to disable caching of package versions from a NuGet feed. The default cache time is set to 30 minutes and I see no way to change this. I cannot find a setting for this and not really able to change it with a module given the way the existing implementation is written.

What is Expected?

I would expect to be able to immediately consume a package I am actively developing once I push it to my NuGet feed. As a work around, I have to explicitly specify the latest version number on the "load" directive, or wait up to 30 minutes.

What version of Cake are you using?

v0.30.0

Are you running on a 32 or 64 bit system?

64 bit

What environment are you running on? Windows? Linux? Mac?

Windows

Are you running on a CI Server? If so, which one?

No

How Did You Get This To Happen? (Steps to Reproduce)

Happens by default.

The problem occurs here:

In the Cake.NuGet.Install.NuGetPackageInstaller class. There is a field called "_sourceCacheContext" of type "NuGet.Protocol.Core.Types.SourceCacheContext" which sets a default cache time of 30 minutes. In the NuGetPackageInstaller.GetNuGetVersion() method on line 195, the call to dependencyInfoResource.ResolvePackages() will returned a cached response within the 30 minute window. I can't find a way to make that not cache the response.

I tried to go down the path of creating a module with my own implementation of the "INuGetPackageInstaller" interface, but I still can't get to the setting in the _sourceCacheContext field to change the cache settings. No matter if I am extending or wrapping the default implementation of "NuGetPackageInstaller", I can't get to the code I would need to change. If at least the "GetNuGetVersion()" method wasn't private static, and was virtual, then I could extend the class to override that method and modify the "sourceCacheContext" parameter before passing it into the base call.

Output Log

It's the following line which indicates the cached response. There is a newer version than "0.0.0.70". CACHE http://myNuGetServer/nuget/FindPackagesById()?id='SortClass.Tools.Cake.Common'&semVerLevel=2.0.0

PS C:\Workspaces\SortClass_GIT\Helpers\helper-reflection> .\build.ps1
Preparing to run build script...
Running build script...
Module directory does not exist.
NuGet.config not found.
Analyzing build script...
Analyzing C:/Workspaces/SortClass_GIT/Helpers/helper-reflection/build.cake...
  CACHE http://myNuGetServer/nuget/FindPackagesById()?id='SortClass.Tools.Cake.Common'&semVerLevel=2.0.0
Found package 'SortClass.Tools.Cake.Common 0.0.0.70' in 'C:/Workspaces/SortClass_GIT/Helpers/helper-reflection/tools'.
Package SortClass.Tools.Cake.Common.0.0.0.70 has already been installed.
Successfully installed 'SortClass.Tools.Cake.Common 0.0.0.70' to C:/Workspaces/SortClass_GIT/Helpers/helper-reflection/tools
Executing nuget actions took 41.43 ms

more logging...

As a feature request

Could there be a setting added to set or disable the cache time? Or could the code in the "NuGetPackageInstaller" class be modified to allow for more extensibility as I described above in the problem section?

Thanks -Joe

bqstony commented 5 years ago

Same issue as here fixed??? https://developercommunity.visualstudio.com/content/problem/210037/nuget-package-manager-only-sees-latest-package-ver.html