Skip to content

Commit

Permalink
Merge pull request #53 from Lombiq/issue/OSOE-775
Browse files Browse the repository at this point in the history
OSOE-775: Fixing direct path return in case of cache busting
  • Loading branch information
wAsnk authored Jan 24, 2024
2 parents 8ab1ee7 + 809e8a9 commit 183f9c4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public string AddFileVersionToPath(PathString requestPathBase, string path)

var assetsSubPath = _mediaFileStore.Combine(
_mediaOption.Value.AssetsRequestPath, Paths.MediaThemeRootFolder, Paths.MediaThemeAssetsFolder);
path = path.Replace(Routes.MediaThemeAssets, assetsSubPath);

// Note that this will work all the time for local files. When a remote storage implementation is used to store
// Media files though (like Azure Blob Storage) then Media Cache will mirror the files locally. Since this only
Expand All @@ -60,14 +59,14 @@ public string AddFileVersionToPath(PathString requestPathBase, string path)
// then the original file will get stuck, and no cache busting parameter will be added until the new file is
// accessed with some other cache busting parameter. So, before the actual cache busting parameter can be added,
// we need to add a random parameter.
var cacheBustedPath = _decorated.AddFileVersionToPath(requestPathBase, path);
var cacheBustedPath = _decorated.AddFileVersionToPath(requestPathBase, path.Replace(Routes.MediaThemeAssets, assetsSubPath));

// This check could be more sophisticated with UriBuilder, but let's keep it simple, since it'll run frequently.
if (!cacheBustedPath.Contains("?v="))
{
return QueryHelpers.AddQueryString(path, "mediatheme", _randomizer.Get().ToTechnicalString());
}

return cacheBustedPath;
return cacheBustedPath.Replace(assetsSubPath, Routes.MediaThemeAssets);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
"SourcePath": "_MediaTheme/Assets/example.png",
"TargetPath": "_MediaTheme/Assets/example.png"
},
{
"SourcePath": "_MediaTheme/Assets/example2.png",
"TargetPath": "_MediaTheme/Assets/example2.png"
},
{
"SourcePath": "_MediaTheme/Templates/Example.liquid",
"TargetPath": "_MediaTheme/Templates/Example.liquid"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<p>This is an example template hosted in Media Theme.</p>
<p>Below is an image also hosted in Media Theme:</p>
{% comment %}
The images are from https://unsplash.com/.
{% endcomment %}
<img src="{{ '~/mediatheme/example.png' | href }}" alt="example" />

<img src="{{ '~/mediatheme/example2.png' | href | append_version }}" alt="example2" />

0 comments on commit 183f9c4

Please sign in to comment.