Skip to content

Method getMergedProperties in ReloadableResourceBundleMessageSource does not set fileTimestamp [SPR-14583] #19152

Closed
@spring-projects-issues

Description

@spring-projects-issues

Igor Stepanov opened SPR-14583 and commented

Hello Spring team,

I'd like to use ReloadableResourceBundleMessageSource to implement REST service to access localized content. And to achieve best performance, I'd like to support caching with "if-modified-since". So the idea is to rely on PropertiesHolder.getFileTimestamp() method to understand if some of the underlying property files was updated or not.

I've extended ReloadableResourceBundleMessageSource and call next method:

protected PropertiesHolder getMergedProperties(Locale locale) {
     PropertiesHolder mergedHolder = this.cachedMergedProperties.get(locale);
     if (mergedHolder != null) {
          return mergedHolder;
     }
     Properties mergedProps = newProperties();
     mergedHolder = new PropertiesHolder(mergedProps, -1);
     String[] basenames = StringUtils.toStringArray(getBasenameSet());
     for (int i = basenames.length - 1; i >= 0; i--) {
          List<String> filenames = calculateAllFilenames(basenames[i], locale);
          for (int j = filenames.size() - 1; j >= 0; j--) {
               String filename = filenames.get(j);
               PropertiesHolder propHolder = getProperties(filename);
               if (propHolder.getProperties() != null) {
                        mergedProps.putAll(propHolder.getProperties());
               }
          }
     }
     PropertiesHolder existing = this.cachedMergedProperties.putIfAbsent(locale, mergedHolder);
     if (existing != null) {
          mergedHolder = existing;
     }
     return mergedHolder;
}

However in current implementation property fileTImestamp is initialized with -1 and never gets updated, so it's not really useful. What do you think about updating it with latest fileTimestamp of the PropertiesHolder instances which are merged into this one?

Moreover, what about adding some setPropertiesChangedCallback() method to make it possible to subscribe to the file updates? In my case this change will allow to push changes to consumer through some message bus and prevent repeated checking through REST interface.


Affects: 4.3.2

Issue Links:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions