AshCookieConsent.Storage (AshCookieConsent v0.1.0)
View SourceThree-tier storage management for consent data.
Implements a hierarchical storage system with the following priority:
Read Priority (fastest to slowest)
- Connection/Socket assigns (request-scoped, in-memory)
- Session (server-side, encrypted)
- Cookie (client-side, signed)
- Database (persistent, audit trail)
Write Strategy
When consent is updated, it's written to all applicable tiers:
- Database (if user is authenticated)
- Cookie (always, for persistence)
- Session (always, for performance)
- Assigns (always, for immediate access)
Examples
# Get consent from any available tier
consent = AshCookieConsent.Storage.get_consent(conn)
# Save consent to all tiers
conn = AshCookieConsent.Storage.put_consent(conn, consent, resource: MyApp.ConsentSettings)
# Delete consent from all tiers
conn = AshCookieConsent.Storage.delete_consent(conn)
Summary
Functions
Deletes consent from all storage tiers.
Gets consent from the highest priority available tier.
Saves consent to all applicable storage tiers.
Syncs consent from database to cookie when consent is loaded.
Syncs consent from cookie to database on user login.
Functions
Deletes consent from all storage tiers.
Examples
conn = AshCookieConsent.Storage.delete_consent(conn)
Gets consent from the highest priority available tier.
Checks in order: assigns → session → cookie → database
Returns the consent map or nil if no consent found.
Examples
consent = AshCookieConsent.Storage.get_consent(conn)
# => %{"terms" => "v1.0", "groups" => ["essential", "analytics"], ...}
Saves consent to all applicable storage tiers.
Options
:resource- Ash resource module for database storage:user_id_key- Key in assigns for user ID (default: :current_user_id):session_key- Session key for consent (default: "consent"):cookie_name- Cookie name (default: "_consent"):skip_database- Skip database save even if authenticated (default: false)
Examples
conn = AshCookieConsent.Storage.put_consent(conn, consent,
resource: MyApp.ConsentSettings
)
Syncs consent from database to cookie when consent is loaded.
Useful for ensuring cookie is up-to-date with latest database consent.
Examples
conn = AshCookieConsent.Storage.sync_from_database(conn,
resource: MyApp.ConsentSettings,
user_id: user.id
)
Syncs consent from cookie to database on user login.
Merges existing cookie consent with database consent, preferring database.
Examples
conn = AshCookieConsent.Storage.sync_on_login(conn,
resource: MyApp.ConsentSettings,
user_id: user.id
)