---
title: "setCacheState(for:cacheMode:coherencyType:action:)"
framework: fskit
role: symbol
role_heading: Instance Method
path: "fskit/fsvolume/setcachestate(for:cachemode:coherencytype:action:)"
---

# setCacheState(for:cacheMode:coherencyType:action:)

Sends a synchronous cache state update request from the module to the kernel.

## Declaration

```swift
func setCacheState(for item: FSItem, cacheMode: FSVolume.DataCacheMode, coherencyType: FSVolume.KernelCacheCoherencyType, action: FSVolume.KernelCacheCoherencyAction) -> (any Error)?
```

## Parameters

- `item`: The item for which to update the cache state.
- `cacheMode`: The new cache mode to apply.
- `coherencyType`: The new coherency type to apply.
- `action`: The action for the kernel to perform on cached data (push, invalidate, update, or revoke).

## Return Value

Return Value An error if the kernel was unable to complete the requested cache state change, or nil on success.

## Discussion

Discussion Volumes conforming to FSVolume.DataCacheHandler call this method to proactively notify the kernel about cache policy changes that need to be applied immediately. This allows module-initiated updates outside the normal open/close/upgrade/downgrade flow. When downgrading coherency type, the action must be FSVolume.KernelCacheCoherencyAction.push, FSVolume.KernelCacheCoherencyAction.pushInvalidate, or FSVolume.KernelCacheCoherencyAction.invalidate to instruct the kernel how to handle cached data. If the action fails, the cache state remains unchanged and the method returns an error. important: This method must be called without holding any module-internal locks. The kernel may issue additional operations back into the module to satisfy cache state changes, which could result in deadlock if locks are held. note: This method is only functional for volumes that conform to FSVolume.DataCacheHandler. For volumes that don’t conform to the protocol, this method returns ENOTSUP.

## See Also

### Managing caching behavior

- [FSItem](fskit/fsitem.md)
- [FSVolume.DataCacheMode](fskit/fsvolume/datacachemode.md)
- [FSVolume.KernelCacheCoherencyType](fskit/fsvolume/kernelcachecoherencytype.md)
- [FSVolume.KernelCacheCoherencyAction](fskit/fsvolume/kernelcachecoherencyaction.md)
