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

add CacheFile backend module #423

Merged
merged 1 commit into from
Oct 14, 2018
Merged

Conversation

wjordan
Copy link
Contributor

@wjordan wjordan commented Jul 18, 2018

This PR adds a new backend module CacheFile. This module overwrites the Base#load_file method to store metadata of loaded file contents, and use this metadata to skip re-loading the same files when their contents haven't changed.

  • The module works with Simple and KeyValue backends, though it's probably more useful in the latter (where the translation store persists across application restarts).
  • Loaded-file metadata is stored in the i18n backend itself, using the :18n locale :load_file scope, with filename as key.
  • When determining whether a file's contents have been changed, it first checks the file-modification time (using File.mtime(filename).to_i), and if they don't match, it additionally checks the file's content (using Digest::SHA2.file(filename).hexdigest). The second check avoids re-loading 'touched' files when the contents haven't changed.
  • I haven't committed to the name yet, could use other suggestions.
  • The tests provide 100% line-by-line coverage, across both Simple and KeyValue backends.
  • My use-case for developing this backend module is to improve per-process memory-usage (and less important, startup time) of a large, heavily-localized Rails application loading ~500mb of localization data stored in .yml files, with minimal application changes.

@wjordan wjordan mentioned this pull request Jul 18, 2018
@radar radar added this to the 1.2.0 milestone Aug 7, 2018
@radar
Copy link
Collaborator

radar commented Oct 14, 2018

Seems pretty sensible to me. Thank you @wjordan!

@radar radar merged commit 40bca10 into ruby-i18n:master Oct 14, 2018
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.

2 participants