Skip to content
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

Added Ability to Transform Generated FileName #221

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

msarchet
Copy link

This will allow people to extend the file path out with any kind of custom behavior that they want
withtout breaking the hash lookup.

An example of how this can be done in a Global.asax file to add a timestamp when the uri is generated to cause cache invalidation for people who don't have a good scheme in place to modify file names.

Registry.FileNameTransformer = (original) =>
{
var originalExtension = original.Split(new char[] {'.'})[1];
return String.Format("RequestReduce{0}.{1}", DateTime.Now.Ticks ,originalExtension);
};

This will allow people to extend the file path out with any kind of custom behavior that they want
withtout breaking the hash lookup.
@mwrock
Copy link
Owner

mwrock commented Oct 21, 2012

Hey thanks for submitting this!. Unfortunately I think this would have negatively unintended consequences. The problem occurs with injecting a non-deterministic element into the file name like DateTime.Now.Ticks. There are a few areas in the code that assume that a Resouce Path will end with this string. For example, at app startup, RR queries the IStore.GetSavedUrls for all Urls of a particular resource type. This looks for paths that EndWith the file name. If this contains the ticks at the time of creation, this file name will change at query time. I totally understand this does not exactly jump out at you and its easy to miss.

A couple things here:

  1. I'm just curious why you want to inject time. Normally I'd think this would be part of a versioning or cache busting technique. However, because RR include the hash of the actual file content into the resource path, versioning and caching should not be material here.
  2. Another approach you could take is to add a means of derriving from UriBuilder and make ParseSignature virtual and also add a virtual GenerateSignature. The default implementation is to hash the byte contents of the file.

Does that make sense?

@msarchet
Copy link
Author

So for the GetSavedUrls I think the only thing that would be needed to be done would be to not modify the RequestReduced part of the string. The tests pass even with any arbitrary information in the string as long as the hash and this part are correct.

Answer to your first question:

So the reason that you might want to insert something that is non-deterministic is the fact that currently you can't invalidate the cache that is being set by RR if you don't modify the file names that are being used in your pages. This works great if you have complete control over all of the files that request reduce is hashing, but in some cases you don't have this.

So by inserting something non-deterministic into the generated URI whenever you flush the content for the pages it will allow the user to get the changed files.

I understand what you are trying to do, even if the machine get's reset don't have them refetch the files since the generated uri will be the same, but in this cases it will mean that if you flush the files they will refetch and cache again which is useful when some one updates a style sheet that is used across pages.

I'll push up a fix for the RequestReduced part and then tell me what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants