Module: CountryIdMemoization
- Extended by:
- ActiveSupport::Concern
- Included in:
- Netcore::Payload
- Defined in:
- app/models/concerns/country_id_memoization.rb
Overview
The memoization is at the instance level, so each instance of the including class will have its own memoized values. This is appropriate for service objects, controllers, and other short-lived objects.
The underlying Country.find_* methods already use Rails cache, so this memoization provides an additional layer of optimization by avoiding even the cache lookup overhead within a single instance.
CountryIdMemoization provides instance-level memoization for country IDs to avoid repeated cache lookups across multiple method calls.
This concern is useful in classes that frequently need to access country IDs (Thailand, Singapore, Malaysia) within the same request/operation lifecycle.
Instance Method Summary collapse
-
#malaysia_id ⇒ Integer
Returns the ID of Malaysia country with instance-level memoization.
-
#singapore_id ⇒ Integer
Returns the ID of Singapore country with instance-level memoization.
-
#thailand_id ⇒ Integer
Returns the ID of Thailand country with instance-level memoization.
Instance Method Details
#malaysia_id ⇒ Integer
Returns the ID of Malaysia country with instance-level memoization
66 67 68 |
# File 'app/models/concerns/country_id_memoization.rb', line 66 def malaysia_id @malaysia_id ||= Country.find_malaysia.id end |
#singapore_id ⇒ Integer
Returns the ID of Singapore country with instance-level memoization
57 58 59 |
# File 'app/models/concerns/country_id_memoization.rb', line 57 def singapore_id @singapore_id ||= Country.find_singapore.id end |
#thailand_id ⇒ Integer
Returns the ID of Thailand country with instance-level memoization
48 49 50 |
# File 'app/models/concerns/country_id_memoization.rb', line 48 def thailand_id @thailand_id ||= Country.find_thailand.id end |