How to signal nanoc that caches need to be expired?

3 views
Skip to first unread message

jmf...@gmail.com

unread,
Jan 4, 2026, 7:35:00 AM (3 days ago) Jan 4
to nanoc

My nanoc site has footers with something like:
 <div MyCompany <%= $current_year %></div>
where  $current_year = Time.now.year

When the year changes the site needs to be recompiled, but nanoc will use the cached value until the cache is invalidated by removing the tmp folder.

My current solution is to store the current year in a txt file in the tmp folder and then hook a script in some where that checks if the year changed and it then deletes the tmp folder and aborts with  a message that says to run "nanoc compile" once more. It works but is very hacky. Any ideas how to do this cleaner? Does nanoc expose a way to tell it to mark its caches as outdated?

jmf...@gmail.com

unread,
Jan 4, 2026, 7:42:58 AM (3 days ago) Jan 4
to nanoc
Answering myself: it occurred to me that I should be able to do something like that @items.create($current_year, ...) in a preprocess block, and then include that on every page. That would add an extra dependency for every page though, so better ideas welcome.

Denis Defreyne

unread,
Jan 4, 2026, 8:43:02 AM (3 days ago) Jan 4
to na...@googlegroups.com
Hey there,

The approach I use is to dynamically set config values in the preprocessor. For example, the Nanoc web site does the following (https://github.com/nanoc/nanoc.app/blob/main/Rules#L4-L12):

preprocess do
  config[:gem_version_info]  = Gem::VERSION
  config[:ruby_version_info] = `ruby --version`.strip
end

Then, elsewhere I can use <%= config[:ruby_version_info] %>. This tracks dependencies properly. You should be able to do the same with the current year, like config[:current_year] = Time.now.year in the preprocessor.

Let me know how this goes!

--
You received this message because you are subscribed to the Google Groups "nanoc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nanoc+un...@googlegroups.com.

jmf...@gmail.com

unread,
Jan 4, 2026, 9:31:58 AM (3 days ago) Jan 4
to nanoc
Excellent, that works nicely. Thanks!
Reply all
Reply to author
Forward
0 new messages