Skip to content

(#3193) Add ability to ignore current http cache #3212

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function script:chocoCmdOperations($commands, $command, $filter, $currentArgumen
$script:chocoCommands = @('-?','search','list','info','install','outdated','upgrade','uninstall','new','pack','push','-h','--help','pin','source','config','feature','apikey','export','help','template','--version')

# ensure these all have a space to start, or they will cause issues
$allcommands = " --debug --verbose --trace --noop --help -? --online --accept-license --confirm --limit-output --no-progress --log-file='' --execution-timeout='' --cache-location='' --proxy='' --proxy-user='' --proxy-password='' --proxy-bypass-list='' --proxy-bypass-on-local --force --no-color --skip-compatibility-checks"
$allcommands = " --debug --verbose --trace --noop --help -? --online --accept-license --confirm --limit-output --no-progress --log-file='' --execution-timeout='' --cache-location='' --proxy='' --proxy-user='' --proxy-password='' --proxy-bypass-list='' --proxy-bypass-on-local --force --no-color --skip-compatibility-checks --ignore-http-cache"

$commandOptions = @{
list = "--id-only --pre --exact --by-id-only --id-starts-with --detailed --prerelease --include-programs --source='' --page='' --page-size=''"
Expand Down
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 have 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 time before 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
Expand Up @@ -79,7 +79,7 @@ public static void ParseArgumentsAndUpdateConfiguration(ICollection<string> args
"Prints out the help menu.",
option => configuration.HelpRequested = option != null)
.Add("online",
"Online - Open help for specified command in default browser application. This option only works when used in combintation with the -?/--help/-h option.",
"Online - Open help for specified command in default browser application. This option only works when used in combintation with the -?/--help/-h option. Available in 2.0.0+",
option => configuration.ShowOnlineHelp = option != null);
}

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 @@ -22,6 +17,16 @@ public class ChocolateySourceCacheContext : SourceCacheContext
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