Module: Parse::Cache::Invalidation

Defined in:
lib/parse/cache/invalidation.rb

Overview

Registers the webhook triggers that keep the identity and role planes honest without relying on application discipline.

Before this, the documented contract asked applications to call Session.invalidate and invalidate_user_roles from their own logout and role-mutation paths. That depends on every application remembering, and it misses role changes made by any other client: a mobile SDK, the dashboard, or Node cloud code. Registering our own triggers moves the responsibility to the SDK and covers writes from every source Parse Server sees.

Parse::Cache::Invalidation.install!(cache)

The TTL remains the backstop. These triggers require the application to run a webhook endpoint Parse Server can reach and to have registered the hooks; unregistered or unreachable, the TTL is the only bound on staleness. TTL and hooks, not TTL or hooks.

Constant Summary collapse

USER_CLASS =

Classes we register against, exposed for tests and diagnostics. Literal class names rather than Parse::Model constants: this file is required from Parse::Client before Parse::Model is defined, and these are fixed Parse Server protocol names, not app-domain classes.

"_User"
SESSION_CLASS =
"_Session"
ROLE_CLASS =
"_Role"
TRIGGERS =
{
  role: [[:after_save, ROLE_CLASS], [:after_delete, ROLE_CLASS]],
  identity: [[:after_save, USER_CLASS],
             [:after_delete, USER_CLASS],
             [:after_logout, SESSION_CLASS]],
}.freeze

Class Method Summary collapse

Class Method Details

.install!(cache) ⇒ Array<Array>

Install the triggers for a cache exposing roles and identity planes.

Parameters:

Returns:



44
45
46
47
48
49
50
51
52
53
# File 'lib/parse/cache/invalidation.rb', line 44

def install!(cache)
  unless cache.respond_to?(:roles) && cache.respond_to?(:identity)
    raise ArgumentError,
          "Parse::Cache::Invalidation requires a cache with role and identity planes"
  end
  registered = []
  registered.concat(install_role_triggers!(cache))
  registered.concat(install_identity_triggers!(cache))
  registered
end