# In-memory Cache

If the Application requires the files to be located physically in the same machine that the server runs but you want to cache the files in memory before serve to achieve the maximum performance then the `DirOptions.Cache` is the field you have to enable.

The `DirOptions.Cache` accepts `DirCacheOptions`:

```go
type DirCacheOptions struct {
	// Enable or disable cache.
	Enable bool
	// Minimum content size for compression in bytes.
	CompressMinSize int64
	// Ignore compress files that match this pattern.
	CompressIgnore *regexp.Regexp
    // The available sever's encodings to be
    // negotiated with the client's needs,
	// common values: gzip, br.
	Encodings []string

    // If greater than zero then prints
    // information about cached files to the stdout.
    // If it's 1 then it prints
    // only the total cached and after-compression
    // reduced file sizes.
	// If it's 2 then it prints it per file too.
	Verbose uint8
}
```

The `DirCacheOptions` allows to cache files based on the available **compressions(!)** too. So if a client requests a gzip version of a file, then the server will be serve the gzip data directly, without the necessity to encode it on fly. This can improve your site's speed to over 50%. This is done automatically by the framework, you just have to provide available Encodings that you want to support and Iris can handle the rest work.

**Usage**

```go
app.HandleDir("/public", iris.Dir("./assets"), iris.DirOptions{
    IndexName: "index.html",
    Cache: iris.DirCacheOptions{
        Enable:          true,
        Encodings:       []string{"gzip"},
        CompressIgnore:  iris.MatchImagesAssets,
        CompressMinSize: 30 * iris.B, // 30 bytes.
    },
})
```

> The `iris.MatchImagesAssets` is just a regular expression which ignores to compress all pre-compressed images for a second time, e.g. `.jpg`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://iris-go.gitbook.io/iris/file-server/memory-cache.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
