Skip to content

Commit

Permalink
(chocolatey#3193) Add ability to ignore current http cache
Browse files Browse the repository at this point in the history
The changes here will add a global option that can be used
by the user to ignore any existing http cache that has been
created prior to the execution of the current command.

Using the option will still create a new cache for the running
execution and reuse that created cache in the current context,
and can be reused normally when not using the argument in the
future.
  • Loading branch information
AdmiringWorm committed Jun 15, 2023
1 parent bdba4f7 commit ad24ead
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,15 @@ private static void SetGlobalOptions(IList<string> args, ChocolateyConfiguration
.Add("skipcompatibilitychecks|skip-compatibility-checks",
"SkipCompatibilityChecks - Prevent warnings being shown before and after command execution when a runtime compatibility problem is found between the version of Chocolatey and the Chocolatey Licensed Extension. Available in 1.1.0+",
option => config.DisableCompatibilityChecks = option != null)
.Add("ignore-http-cache",
"IgnoreHttpCache - Ignore any HTTP caches that has previously been created when querying sources, and create new caches. Available in 2.1.0+",
option =>
{
if (option != null)
{
config.CacheExpirationInMinutes = -1;
}
});
;
},
(unparsedArgs) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public ChocolateyConfiguration()
RegularOutput = true;
PromptForConfirmation = true;
DisableCompatibilityChecks = false;
CacheExpirationInMinutes = 30;
SourceType = SourceTypes.Normal;
Information = new InformationCommandConfiguration();
Features = new FeaturesConfiguration();
Expand Down Expand Up @@ -340,6 +341,15 @@ private void AppendOutput(StringBuilder propertyValues, string append)
public bool ApplyInstallArgumentsToDependencies { get; set; }
public bool IgnoreDependencies { get; set; }

/// <summary>
/// Gets or sets the the time the cache is considered to have expired in minutes.
/// </summary>
/// <value>
/// The cache expiration in minutes.
/// </value>
/// <remarks>specifying a negative number disables the caching completely.</remarks>
public int CacheExpirationInMinutes { get; set; }

public bool AllowDowngrade { get; set; }
public bool ForceDependencies { get; set; }
public string DownloadChecksum { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace chocolatey.infrastructure.app.nuget
namespace chocolatey.infrastructure.app.nuget
{
using System;
using System.Threading;
using Alphaleonis.Win32.Filesystem;
using configuration;
using chocolatey.infrastructure.app.configuration;
using NuGet.Protocol.Core.Types;

public class ChocolateySourceCacheContext : SourceCacheContext
Expand All @@ -20,8 +15,18 @@ public class ChocolateySourceCacheContext : SourceCacheContext
private readonly string _chocolateyCacheLocation;

public ChocolateySourceCacheContext(ChocolateyConfiguration config)
{
{
_chocolateyCacheLocation = config.CacheLocation;

if (config.CacheExpirationInMinutes <= 0)
{
MaxAge = DateTime.UtcNow;
RefreshMemoryCache = true;
}
else
{
MaxAge = DateTime.UtcNow.AddMinutes(-config.CacheExpirationInMinutes);
}
}

public override string GeneratedTempFolder
Expand Down

0 comments on commit ad24ead

Please sign in to comment.