Skip to content

cachedb_local: raise event on cache entry expiry#3853

Open
dondetir wants to merge 1 commit intoOpenSIPS:masterfrom
dondetir:feature/cachedb-local-expiry-event
Open

cachedb_local: raise event on cache entry expiry#3853
dondetir wants to merge 1 commit intoOpenSIPS:masterfrom
dondetir:feature/cachedb-local-expiry-event

Conversation

@dondetir
Copy link
Copy Markdown

Summary

Add E_CACHEDB_LOCAL_EXPIRED event support, allowing users to be notified via event_route when cached entries expire.

Usage

event_route[E_CACHEDB_LOCAL_EXPIRED] {
    xlog("expired: $param(key) = $param(value) in $param(collection)\n");
    # safe to access the cache from within this handler
    cache_store("local", "reacted_to_$param(key)", "handled", 60);
}

Event Parameters

Parameter Description
key The key of the expired cache entry
value The value of the expired cache entry
collection The cache collection name

Implementation Details

  • The event is raised during the periodic cleanup timer (cache_clean_period), not during lazy expiry on access
  • Events are raised outside the per-bucket hash table lock to prevent deadlocks when the event_route handler accesses the cache — expired entry data is copied to pkg memory before lock release
  • Uses the standard EVI (Event Interface) framework following the same pattern as usrloc (E_UL_CONTACT_DELETE) and dialog (E_DLG_STATE_CHANGED)
  • evi_probe_event() check avoids parameter setup overhead when no subscribers exist

Testing

  • Builds clean, zero warnings in new code
  • All 2545 unit tests pass
  • Runtime verified: event fires with correct key/value/collection parameters
  • Deadlock test: event handler successfully writes back to cache from within event_route — no deadlock

Closes #3735

Add E_CACHEDB_LOCAL_EXPIRED event support, allowing users to be
notified via event_route when cached entries expire.  The event is
raised during the periodic cleanup timer (cache_clean_period) with
the following parameters:

 - key: the expired cache key
 - value: the expired cache value
 - collection: the cache collection name

Example usage in the OpenSIPS script:

  event_route[E_CACHEDB_LOCAL_EXPIRED] {
      xlog("expired: $param(key) = $param(value)\n");
  }

The event is raised outside the per-bucket hash table lock to avoid
deadlocks when the event_route handler accesses the cache.  Expired
entry data is copied to pkg memory before lock release and freed
after the event is dispatched.

Uses the standard EVI (Event Interface) framework following the same
pattern as usrloc and dialog modules.  An evi_probe_event() check
avoids parameter setup overhead when no subscribers exist.

Closes OpenSIPS#3735
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] event_route for cache_local expiry

1 participant