# cacheBy() function · @imqueue/pg-cache

Source: https://imqueue.org/api/pg-cache/latest/pg-cache.cacheby/
Published: 2026-08-04
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/pg-cache 5.0.6 — generated reference, not hand-written

Decorator factory `@cacheBy`(Model, CacheByOptions) This decorator should be used on a service methods, to set the caching rules for a method. Caching rules within this decorator are defined by a passed model, which is treated as a root model of the call and it analyzes cache invalidation based on passed runtime fields arguments, which prevents unnecessary cache invalidations. So it is more intellectual way to invalidate cache instead of any changes on described list of tables.

**Signature:**

```typescript
export declare function cacheBy(model: typeof Model, options?: CacheByOptions): MethodDecorator;
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| model | typeof Model |  |
| options | [CacheByOptions](https://imqueue.org/api/pg-cache/latest/pg-cache.cachebyoptions/) | _(Optional)_ |


**Returns:**

[MethodDecorator](https://imqueue.org/api/pg-cache/latest/pg-cache.methoddecorator/)

