---
title: "cache(_:willEvictObject:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nscachedelegate/cache(_:willevictobject:)"
---

# cache(_:willEvictObject:)

Called when an object is about to be evicted or removed from the cache.

## Declaration

```swift
optional func cache(_ cache: NSCache<AnyObject, AnyObject>, willEvictObject obj: Any)
```

## Parameters

- `cache`: The cache with which the object of interest is associated.
- `obj`: The object of interest in the cache.

## Discussion

Discussion It is not possible to modify cache from within the implementation of this delegate method.
