---
title: "open(_:modes:cacheMode:context:replyHandler:)"
framework: fskit
role: symbol
role_heading: Instance Method
path: "fskit/fsvolume/datacachehandler/open(_:modes:cachemode:context:replyhandler:)"
---

# open(_:modes:cacheMode:context:replyHandler:)

Opens an item with cache mode negotiation.

## Declaration

```swift
func open(_ item: FSItem, modes: FSVolume.OpenModes, cacheMode: FSVolume.DataCacheMode, context: FSContext, replyHandler reply: @escaping @Sendable (FSOpenItemResult?, (any Error)?) -> Void)
```

```swift
func open(_ item: FSItem, modes: FSVolume.OpenModes, cacheMode: FSVolume.DataCacheMode, context: FSContext) async throws -> FSOpenItemResult
```

## Parameters

- `item`: The item to open.
- `modes`: The open modes, such as read and write.
- `cacheMode`: The requested cache mode, indicating what data is eligible for caching.
- `context`: An object that enables context-aware file system decisions throughout the operation.

## Discussion

Discussion ::::: Swift :::::::::: reply: A block or closure to indicate success or failure. If opening succeeds, pass an instance of FSOpenItemResult containing the granted FSVolume.KernelCacheCoherencyType, along with a nil error. If opening fails, pass the relevant error as the second parameter; FSKit ignores the FSOpenItemResult instance in this case. For an async Swift implementation, there’s no reply handler; simply return the result instance or throw an error. :::::::::::::::::::: ::::: ObjC :::::::::: result: A block or closure to indicate success or failure. If opening succeeds, pass an instance of FSOpenItemResult containing the granted FSVolume.KernelCacheCoherencyType, along with a nil error. If opening fails, pass the relevant error as the second parameter; FSKit ignores the FSOpenItemResult instance in this case. For an async Swift implementation, there’s no reply handler; simply return the result instance or throw an error. :::::::::::::::::::: Discussion FSKit calls this method when opening a file, providing the requested cache mode. The module implementation determines what level of caching it can support for this item, considering factors such as server lease availability, file locking state, or other coherency requirements. The granted coherency type must be compatible with the requested cache mode, as defined by the cache-mode-to-coherency-type mappings documented in the discussion of the FSVolume.DataCacheHandler protocol. If the module grants a coherency type that exceeds the cache mode’s permissions, the kernel downgrades to a valid coherency type.

## See Also

### Opening and closing items

- [FSOpenItemResult](fskit/fsopenitemresult.md)
- [close(_:context:replyHandler:)](fskit/fsvolume/datacachehandler/close(_:context:replyhandler:).md)
- [FSVolume.DataCacheMode](fskit/fsvolume/datacachemode.md)
- [FSContext](fskit/fscontext.md)
