-
Notifications
You must be signed in to change notification settings - Fork 83
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
Caching file modification times. #26
Comments
Hi @jjeffery, thanks for your feedback on vfsgen, and for and creating this issue! I'd like to discuss this to better understand the problem and solution space, before we get to implementation details. vfsgen fully supports and respects the modification times in the source virtual filesystem (VFS), and preserves them in the output VFS. Running it multiple times on same input should produce same output (i.e., it's deterministic). It even normalizes the timezone as UTC, so that people running vfsgen in different parts of the world (i.e., where their local timezone is different) would still produce same output. So, I want to learn more about this:
What does your |
Thanks for the reply @shurcooL. I'm keen to discuss and see if perhaps there is a better way to achieve what I am trying to do. Perhaps there is. Apologies for As you say, vfsgen does respect the file modification time, and if that does not change then the output of vfsgen is consistent. I take your point about converting to UTC and notice that I omitted to put a trailing "Z" in my example timestamps above, which would be necessary. Where I run into issues is when the modification time changes but nothing else changes. In my experience the most common examples of this are:
In these cases I would like vfsgen to recognize that the MD5 (or SHA1, whatever) is the same and assign a previously allocated modification time so that the generated code matches exactly. The attached screenshot might help explain. I have just checked out one of our repos and run As an aside, I'm not sure why the previous version is showing fractions of a second and the recently generated code shows to second precision only. As far as I can see the code is just using |
(Sorry for the delay; I lost track of this issue and forgot to get back to you.) Thanks for providing that info.
I see. That makes sense. I run into the source code being checked out causing modtimes to change on disk occasionally too.
Right, so Question about that approach, where do you anticipate the cache would be stored? Imagine if I check something in, and another person pulls the same repo on a different computer. If the cache isn't a part of the repo, they're unlikely to be able to access it, right? Also, CI servers are probably not going to get a copy of your cache either. Here's what I'm thinking so far. The whole approach of potentially using a cache is something that happens before vfsgen produces the output. It's pretty orthogonal from the actual generation process and can be cleanly abstracted out. The code that does it can be a part of vfsgen, or it can be a part of a separate tool. However, for prototype purposes, I think your best bet would be to prototype it as a separate tool from vfsgen. Here's what you can do, create a tool that caches modtimes and hashes, and then give it the ability to "restore" old cached modtimes. It would literally write to disk and change modtimes of files on disk to the saved values. Then, vfsgen would pick up those new modtimes that are the values you want. How does such an approach sound to you? In the end, I think that caching modtimes is just one potential approach to solve this overarching issue, and perhaps there's other ways. I'm open to keep thinking about this problem. |
Just to follow up that thought, such code/tool doesn't have to write to disk necessarily, it can simply provide a VFS wrapper that overrides modtimes of the underlying source VFS. |
Thanks for taking the time to consider this. You are absolutely correct in saying that our hypothetically modified My initial implementation thought was to introduce a file with a special name, perhaps I've already included a pretty simple example of what the contents of I can well understand that magic filenames are not to everyone's taste, alternative implementations might be to include an additional command line argument to Your point about this being an orthogonal concern to the main job of I guess that the only real motivation for including this in Never mind, I'm getting the impression that perhaps it is not something anyone else has had issue with. Feel free to close this issue, and I'll put together something that restores the timestamps prior to generating with |
Sounds good, thanks! As I said in my previous comment, I'm okay to keep this open with It'd be great if you could post any updates about your experimentation and success, and tell me how well it works, etc. If in the end it's something that's worthwhile to integrate into vfsgen, meaning it provides enough value to justify the increased complexity, I would certainly consider integrating it. That said, I really want to think more and hopefully come up with a simpler solution. |
Nice package! Though I've not used it in any app yet. It would be nice if HTTP caching headers could be provided automatically ( We should be overwrite default behavior or disable it - could be just a function that has access to file body and a KV-Store of file/info,header. |
Thanks @dc0d. This issue is about some sort caching of file modify dates, for files that are not modified between invocations of vfsgen. Not app-layer HTTP caching. Although the two might be related in some ways. Still, if you'd like to discuss that, it's better to open a separate issue about that, to avoid crosstalk. |
My mistake; sorry. |
No problem! If you create that issue, we can discuss it further there. |
I also think this would be very useful, as I plan on checking in the go generated file into source control, it would be nice to have a build script that is idempotent, and as such be able to run |
@shurcooL what's the usefulness of saving the modtime? Maybe this could be added to options and set using a static value? |
Assuming that file modification time doesn't actually matter, and only the content of the file matters, the above PR allows a user to set the filemod time to the the time zero value. cc @jjeffery |
Mostly to enable HTTP caching. When files have accurate modification times, and a request comes in with a
I agree that'd be nice, but I still don't know of a great way of making that possible. |
I needed |
In the stated use case where there is say |
Hi and thanks for the effort you have put into this excellent package.
One enhancement that I would find useful is the caching of file modification times. What I find is that if I run "make generate" on my project the generated vfsgen files can have different modification times for the files even if they have not changed. This is not devastating but I for one would find it handy if the generated vfsgen files did not change unless the input files were in fact different.
I was thinking that one way to achieve this might be to generate a JSON file that was keyed on file name and contained a digest of the file name and a modification time. If the file had not changed then the modification time was used. If the file had changed then the current time would be used and the JSON file would be updated accordingly:
Now I realise that this would be a significant addition of functionality and your contribution guidelines indicate that it might be considered out of scope for the package. So before I start serious work on a PR, could I ask for your thoughts on this idea?
The text was updated successfully, but these errors were encountered: