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

Command icon 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

valic created an issue. See original summary.

valic’s picture

Version: 3.0.x-dev » 3.x-dev

introfini made their first commit to this issue’s fork.

introfini’s picture

Status: Active » Needs review

Added 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.

valic’s picture

Status: Needs review » Reviewed & tested by the community

Tnx, merging

valic’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.