# Self-Refreshing Webhooks Cache

CybusMQ includes a self-refreshing webhooks cache that enables efficient authentication and authorization at scale. The cache proactively refreshes authorization objects and prioritizes low-latency message routing over strict expiration enforcement.

You can use webhooks endpoints to implement custom authentication and authorization logic. CybusMQ caches authorization objects for faster reuse, but these cached objects have an expiration time after which they need to be re-authenticated through the webhook endpoint.

## How It Works

### Proactive Refresh

CybusMQ uses a refreshing mechanism that proactively updates cached authorization objects before they expire. Instead of waiting until an MQTT publish operation to discover an object has expired, the cache refreshes objects in the background. This approach:

* Eliminates delays in publish operations caused by re-authentication.
* Distributes webhook requests smoothly over time instead of in bursts.
* Prevents overloading the webhook endpoint during specific traffic patterns.

### Allowing Cache Behavior

To support environments with hundreds of thousands of authorization objects, the cache uses an allowing approach. When the webhook endpoint cannot keep up with the broker's performance and gets overloaded with requests, expired objects automatically have their validity extended.

This design prioritizes low-latency message routing over strict authorization expiration, based on the observation that authorization changes happen relatively rarely in typical deployments.

## Benefits

* **Low latency**: Publish operations don't wait for authorization checks.
* **Smooth endpoint load**: Webhook requests are distributed evenly over time.
* **High scalability**: Handles authorization objects at this scale.
* **Graceful degradation**: Continues operating when webhook endpoints are overloaded.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cybus.io/broker/cybusmq/configuration/self-refreshing-webhooks-cache.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
