---
application: "Intervention Image"
version: "Version 2"
status: "eol"
---

# Image::cache

## Cached image processing



> public Intervention\Image\ImageManager cache(Closure $callback, [int $lifetime, [bool $returnObj]])

Method to create a new cached image instance from a **Closure callback**. Pass a **lifetime** in minutes for the callback and decide whether you want to get an Intervention Image instance as **return value** or just receive the image stream.

**Note: This method requires the additional package intervention/imagecache.**

### Parameters

#### callback
A closure containing the operations on an image, defining the cached image.

#### lifetime (optional)
The lifetime in minutes of the image callback in the cache. (Default: `5`)

#### returnObj (optional)
Decide if you want the method to return an Intervention Image instance or (by default) the image stream.

### Return Values
Mixed - based on ```returnObj``` parameter.

### Examples

```php
// create a cached image and set a lifetime and return as object instead of string
$img = Image::cache(function($image) {
   $image->make('public/foo.jpg')->resize(300, 200)->greyscale();
}, 10, true);
```

### See also
- [Further Information about Image Caching](https://image.intervention.io/v2/usage/cache.md)

---

## Become a Sponsor

### Intervention Image needs your help to keep the project going

Intervention Image is non-commercial, open source licensed and completely free to use. The considerable
effort required to maintain and develop the software is only possible with the financial support
of sponsors. There are two ways in which you can support this project.

- Support via [GitHub Sponsors](https://github.com/sponsors/Intervention)
- Support via [Ko-Fi](https://ko-fi.com/interventionphp)