# lambda-local-caching

> Library to cache variables in AWS Lambda

Latest version **0.0.3** (published 2021-08-26) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install lambda-local-caching
pnpm add lambda-local-caching
yarn add lambda-local-caching
bun add lambda-local-caching
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2021-08-26 |
| First published | 2021-08-26 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 14 |
| Dependencies | 0 |
| Unpacked size | 21.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Yaohan Zais |
| Maintainers | yaohancz |
| Keywords | caching, lambda, projen, typescript |

## Links

- npm: https://www.npmjs.com/package/lambda-local-caching
- Repository: https://github.com/yaohanzaismondo/Lambda-Local-Caching
- Homepage: https://github.com/yaohanzaismondo/Lambda-Local-Caching#readme
- Issues: https://github.com/yaohanzaismondo/Lambda-Local-Caching/issues
- npm.io page: https://npm.io/package/lambda-local-caching

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.0.3 (latest) — 2021-08-26
- 0.0.2 — 2021-08-26

## README

# Lambda-Local-Caching

Library for setting and retrieving local caching in AWS Lambda.

## Overview

Anything declared outside the handler function (in global variable) is reused between invocations. The cached variable will live as long as the lambda container runs. As a result, there is no guarantee about the lifetime of the cached variable itself.

This library provides an expiry of each cached variable. The default caching expiry is 5 minutes.

## Installation

```console
npm i lambda-local-caching
```

## How to Use

### Cache Variable
```javascript
import {cacheVariable, getCacheVariable} from 'lambda-local-caching'

const variableToBeCachedValue = 'abcd'
const key = 'variable-to-be-cached'
cacheVariable<string>(key, variableToBeCachedValue, 600)

```
### Getting Cached Variable
```javascript
import {cacheVariable, getCacheVariable} from 'lambda-local-caching'

const variableToBeCachedValue = 'abcd'
const key = 'variable-to-be-cached'
cacheVariable<string>(key, variableToBeCachedValue)

const result = getCacheVariable<string>(key)

console.log(result.isSuccessful) // true
console.log(result.value) //This will print out abcd

```

#### Unsuccessful retrieval
```javascript
import {getCacheVariable} from 'lambda-local-caching'

const key = 'variable-to-be-cached'
const result = getCacheVariable<string>(key)

console.log(result.isSuccessful) // false
console.log(result.type) // FailureType.NotFound


cacheVariable<string>(key, 'some-value', 0) //expired
console.log(result.isSuccessful) // false
console.log(result.type) // FailureType.Expired
```

### General Use Case (Getting & Setting the cached)
```javascript
import {cacheVariable, getCacheVariable} from 'lambda-local-caching'

const key = 'variable-to-be-cached'

function getSomething(): string {
  const result = getCacheVariable<string>(key)
  if (!result.isSuccessful) {
    const value = getSomeOtherThingToBeCached()
    cacheVariable<string>(key, value)
    return value
  }
  return result.value
}
```

---
_Source: https://npm.io/package/lambda-local-caching · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
