Skip to content

Commit 06acb28

Browse files
authoredJun 15, 2023
Merge pull request chocolatey#3212 from AdmiringWorm/feature/3193-provide-option-for-chocolatey
(chocolatey#3193) Add ability to ignore current http cache
2 parents bdba4f7 + 3b6ff3a commit 06acb28

File tree

5 files changed

+34
-10
lines changed

5 files changed

+34
-10
lines changed
 

‎src/chocolatey.resources/helpers/ChocolateyTabExpansion.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function script:chocoCmdOperations($commands, $command, $filter, $currentArgumen
3838
$script:chocoCommands = @('-?','search','list','info','install','outdated','upgrade','uninstall','new','pack','push','-h','--help','pin','source','config','feature','apikey','export','help','template','--version')
3939

4040
# ensure these all have a space to start, or they will cause issues
41-
$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"
41+
$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"
4242

4343
$commandOptions = @{
4444
list = "--id-only --pre --exact --by-id-only --id-starts-with --detailed --prerelease --include-programs --source='' --page='' --page-size=''"

‎src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs

+9
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,15 @@ private static void SetGlobalOptions(IList<string> args, ChocolateyConfiguration
441441
.Add("skipcompatibilitychecks|skip-compatibility-checks",
442442
"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+",
443443
option => config.DisableCompatibilityChecks = option != null)
444+
.Add("ignore-http-cache",
445+
"IgnoreHttpCache - Ignore any HTTP caches that have previously been created when querying sources, and create new caches. Available in 2.1.0+",
446+
option =>
447+
{
448+
if (option != null)
449+
{
450+
config.CacheExpirationInMinutes = -1;
451+
}
452+
});
444453
;
445454
},
446455
(unparsedArgs) =>

‎src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs

+10
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public ChocolateyConfiguration()
3838
RegularOutput = true;
3939
PromptForConfirmation = true;
4040
DisableCompatibilityChecks = false;
41+
CacheExpirationInMinutes = 30;
4142
SourceType = SourceTypes.Normal;
4243
Information = new InformationCommandConfiguration();
4344
Features = new FeaturesConfiguration();
@@ -340,6 +341,15 @@ private void AppendOutput(StringBuilder propertyValues, string append)
340341
public bool ApplyInstallArgumentsToDependencies { get; set; }
341342
public bool IgnoreDependencies { get; set; }
342343

344+
/// <summary>
345+
/// Gets or sets the time before the cache is considered to have expired in minutes.
346+
/// </summary>
347+
/// <value>
348+
/// The cache expiration in minutes.
349+
/// </value>
350+
/// <remarks>specifying a negative number disables the caching completely.</remarks>
351+
public int CacheExpirationInMinutes { get; set; }
352+
343353
public bool AllowDowngrade { get; set; }
344354
public bool ForceDependencies { get; set; }
345355
public string DownloadChecksum { get; set; }

‎src/chocolatey/infrastructure.app/configuration/ConfigurationOptions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static void ParseArgumentsAndUpdateConfiguration(ICollection<string> args
7979
"Prints out the help menu.",
8080
option => configuration.HelpRequested = option != null)
8181
.Add("online",
82-
"Online - Open help for specified command in default browser application. This option only works when used in combintation with the -?/--help/-h option.",
82+
"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+",
8383
option => configuration.ShowOnlineHelp = option != null);
8484
}
8585

‎src/chocolatey/infrastructure.app/nuget/ChocolateySourceCacheContext.cs

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
7-
namespace chocolatey.infrastructure.app.nuget
1+
namespace chocolatey.infrastructure.app.nuget
82
{
3+
using System;
94
using System.Threading;
105
using Alphaleonis.Win32.Filesystem;
11-
using configuration;
6+
using chocolatey.infrastructure.app.configuration;
127
using NuGet.Protocol.Core.Types;
138

149
public class ChocolateySourceCacheContext : SourceCacheContext
@@ -22,6 +17,16 @@ public class ChocolateySourceCacheContext : SourceCacheContext
2217
public ChocolateySourceCacheContext(ChocolateyConfiguration config)
2318
{
2419
_chocolateyCacheLocation = config.CacheLocation;
20+
21+
if (config.CacheExpirationInMinutes <= 0)
22+
{
23+
MaxAge = DateTime.UtcNow;
24+
RefreshMemoryCache = true;
25+
}
26+
else
27+
{
28+
MaxAge = DateTime.UtcNow.AddMinutes(-config.CacheExpirationInMinutes);
29+
}
2530
}
2631

2732
public override string GeneratedTempFolder

0 commit comments

Comments
 (0)