Problem/Motivation
If you having geo based project where cacheability need to depend on geo country context, you need to to write it your self.
We need to provide default one, which projects can use if they have need for it
Steps to reproduce
Proposed resolution
Add cache context based on current country.
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork geoip-3455643
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
valicComment #5
introfini commentedAdded a geoip_country cache context in MR !7.
This provides a built-in cache context that varies render arrays by the visitor's geolocated country code. Without it, every project doing country-based rendering (pricing, block visibility, etc.) needs to
implement their own.
Usage:
$build['#cache']['contexts'][] = 'geoip_country';The implementation uses proper dependency injection (RequestStack + GeoLocation service), returns a lowercased country code (e.g., pt, us), and falls back to an empty string when geolocation is unavailable.
We've been using a custom version of this in production for country-based pricing with Drupal Commerce and this formalizes it as part of the module.
Comment #6
valicTnx, merging
Comment #8
valic