# @item-enonic-types/lib-cache

> TypeScript types for Enonic XP

Latest version **3.0.0** (published 2026-09-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @item-enonic-types/lib-cache
pnpm add @item-enonic-types/lib-cache
yarn add @item-enonic-types/lib-cache
bun add @item-enonic-types/lib-cache
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2026-09-24 |
| First published | 2022-10-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Tom Arild Jakobsen |
| Maintainers | tajakobsen |
| Keywords | enonic |

## Links

- npm: https://www.npmjs.com/package/@item-enonic-types/lib-cache
- Repository: https://github.com/ItemConsulting/enonic-types
- Homepage: https://github.com/ItemConsulting/enonic-types#readme
- Issues: https://github.com/ItemConsulting/enonic-types/issues
- npm.io page: https://npm.io/package/@item-enonic-types/lib-cache

## Recent versions

- 3.0.0 (latest) — 2026-09-24
- 2.2.1 — 2024-12-12
- 2.2.0 — 2023-06-06
- 2.1.1 — 2022-10-26

## README

# TypeScript types for Enonic XP

> [!NOTE]
> There now exists [official TypeScript-types](https://www.npmjs.com/org/enonic-types) from Enonic.
> The new purpose of this library will be to provide types for all the libraries that doesn't have official support yet.

## Installing individual packages

You can install individual packages with support for Enonic libraries like this:

You can find the [complete list of supported packages on npm](https://www.npmjs.com/org/item-enonic-types).

```bash
npm i --save-dev @item-enonic-types/global
npm i --save-dev @item-enonic-types/lib-menu
```

## Update tsconfig.json

We recommend using [starter-tsup](https://github.com/enonic/starter-tsup) as the base of your XP-project.

To add the TypeScript-types you need to update your *tsconfig.json* with the following:

```json
{
  "compilerOptions": {
    "target": "es5",
    "strict": true,
    "sourceMap": true,
    "allowJs": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "strictNullChecks": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "types": ["@item-enonic-types/global"],
    "rootDirs": [
      "./src/main/resources",
      "./.xp-codegen"
    ],
    "paths": {
      "/lib/xp/*": ["./node_modules/@enonic-types/lib-*"],
      "/lib/*": [ "./node_modules/@item-enonic-types/lib-*" ,"./src/main/resources/lib/*"],
      "/site/*": ["./src/main/resources/site/*" ,"./.xp-codegen/site/*"]
    }
  },
  "include": [
    "./.xp-codegen/**/*",
    "./src/main/resources/**/*"
  ],
  "exclude": ["./build/*"]
}
```

## Code generation

We recommend using this library together with the [xp-codegen-plugin](https://github.com/ItemConsulting/xp-codegen-plugin) Gradle plugin. *xp-codegen-plugin* will create a TypeScript `type` for your content-types. Those interfaces will be very useful together with this library.

## Example

We have an Enonic service that returns an article by id.

```typescript
import type { Article } from "../../site/content-types"; // 1
import { get as getOne, type Content } from "/lib/xp/content"; // 2

type ContentArticle = Content<Article, "my.awesome.project:Article">;

export function get(req: XP.Request): XP.Response { // 3
  const content = getOne<ContentArticle>({ 
    key: req.params.id!
  });

  assertIsDefined(content); // 4

  const article: Article = content.data;
  
  return {
    status: 200,
    body: article
  }
}

/** 
 * Create this function in a utilities file of your choice... 
 */
function assertIsDefined<T>(value: T): asserts value is NonNullable<T> {
  if (value === undefined || value === null) {
    throw new Error(`${value} is not defined`);
  }
}
```

 1. We import an `type Article = { ... }` generated by [xp-codegen-plugin](https://github.com/ItemConsulting/xp-codegen-plugin).
 2. The standard XP-libraries are mapped to their paths by the change to *tsconfig.json*.
 3. We use `XP.Request` and `XP.Response` to control the shape of our controller.
 4. `content` is of the type `Content<Article> | null`, but we can "assert" that it is not nullable (or throw an exception here if it is).
 
## Supported libraries

 * [CacheLibrary](./packages/cache)
 * [ExplorerLibrary](./packages/explorer)
 * [HttpClientLibrary](./packages/http-client)
 * [MenuLibrary](./packages/menu)
 * [QRCodeLibrary](./packages/qrcode)
 * [RecaptchaLibrary](./packages/recaptcha)
 * [RouterLibrary](./packages/router) 
 * [SqlLibrary](./packages/sql) 
 * [TextEncodingLibrary](./packages/text-encoding)
 * [ThymeleafLibrary](./packages/thymeleaf)
 * [XsltLibrary](./packages/xslt)

---
_Source: https://npm.io/package/@item-enonic-types/lib-cache · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
