From 4807e3cc633cb9586824d28a87e9413a67baf45d Mon Sep 17 00:00:00 2001 From: James Brundage <+@noreply.github.com> Date: Wed, 2 Jul 2025 16:51:35 -0700 Subject: [PATCH 1/2] feat: JSON-LD caching ( Fixes #10 ) --- Commands/Get-JsonLD.ps1 | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Commands/Get-JsonLD.ps1 b/Commands/Get-JsonLD.ps1 index 5ace9e8..c69504e 100644 --- a/Commands/Get-JsonLD.ps1 +++ b/Commands/Get-JsonLD.ps1 @@ -22,10 +22,15 @@ function Get-JsonLD { # The URL that may contain JSON-LD data [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] [Uri] - $Url + $Url, + + # If set, will force the request to be made even if the URL has already been cached. + [switch] + $Force ) begin { + # Create a pattern to match the JSON-LD script tag $linkedDataRegex = [Regex]::new(@' (? )) # Anything until the end tag is JSONContent ) '@, 'IgnoreCase,IgnorePatternWhitespace','00:00:00.1') + + # Initialize the cache for JSON-LD requests + if (-not $script:JsonLDRequestCache) { + $script:JsonLDRequestCache = [Ordered]@{} + } } process { - $restResponse = Invoke-RestMethod -Uri $Url + $restResponse = + if ($Force -or -not $script:JsonLDRequestCache[$url]) { + $script:JsonLDRequestCache[$url] = Invoke-RestMethod -Uri $Url + $script:JsonLDRequestCache[$url] + } else { + $script:JsonLDRequestCache[$url] + } foreach ($match in $linkedDataRegex.Matches("$restResponse")) { foreach ($jsonObject in $match.Groups['JsonContent'].Value | From 422721faf947b8f8d6fd5f074414d0b89dba09d9 Mon Sep 17 00:00:00 2001 From: James Brundage <+@noreply.github.com> Date: Wed, 2 Jul 2025 17:02:13 -0700 Subject: [PATCH 2/2] release: JSON-LD 0.1 Updating module version and CHANGELOG --- CHANGELOG.md | 14 ++++++++++++++ JSON-LD.psd1 | 10 +++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f3830db --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ +> Like It? [Star It](https://github.com/PowerShellWeb/JSON-LD) +> Love It? [Support It](https://github.com/sponsors/StartAutomating) + +## JSON-LD 0.1 + +Caching JSON-LD requests + +## JSON-LD 0.0.1 + +Get Linked Data from any page + +* Initial Release of JSON-LD Module (#1) + * `Get-JsonLD` gets linked data (#2) + * `Get-JsonLD` is aliased to `jsonLD` and `json-ld` diff --git a/JSON-LD.psd1 b/JSON-LD.psd1 index 4fbde64..d4fc7b3 100644 --- a/JSON-LD.psd1 +++ b/JSON-LD.psd1 @@ -1,13 +1,13 @@ @{ RootModule = 'JSON-LD.psm1' - ModuleVersion = '0.0.1' + ModuleVersion = '0.1' GUID = '4e65477c-012c-4077-87c7-3e07964636ce' - Author = 'JamesBrundage' + Author = 'James Brundage' CompanyName = 'Start-Automating' Copyright = '(c) 2025 Start-Automating.' Description = 'Get JSON Linked Data with PowerShell' FunctionsToExport = 'Get-JsonLD' - AliasesToExport = 'jsonLD', 'json-ld' + AliasesToExport = 'jsonLD', 'json-ld' PrivateData = @{ PSData = @{ # Tags applied to this module. These help with module discovery in online galleries. @@ -20,6 +20,10 @@ > Like It? [Star It](https://github.com/PowerShellWeb/JSON-LD) > Love It? [Support It](https://github.com/sponsors/StartAutomating) +## JSON-LD 0.1 + +Caching JSON-LD requests + Get Linked Data from any page ## JSON-LD 0.0.1