Skip to content

[Proposal] Cache local configs when the argument is frozen #168

@saverio-kantox

Description

@saverio-kantox

Often, the local config is used in several parts of an application. For example:

NY_OFFICE_CONFIG = {
  holidays: ['2017-07-04'],
  end_of_working_day: '17:00'
}.freeze

ABU_DHABI_OFFICE_CONFIG = {
  holidays: ['2017-08-08'],
  work_week: %w(sun mon tue wed thu)
}.freeze

BusinessDays::Config.with(NY_OFFICE_CONFIG) { 3.business_hours.from_now }
BusinessDays::Config.with(ABU_DHABI_OFFICE_CONFIG) { 4.business_days.ago }

Clearly, continually creating and destroying the local configs could be avoided, if the generated configs were cached. If the same frozen object is passed again, one could reuse the previous local config.

I can do that if you are interested.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions