<div align="center">

<img src="https://github.com/Bejibun-Framework/bejibun/blob/master/public/images/bejibun.png?raw=true" width="150" alt="Bejibun" />

![GitHub top language](https://img.shields.io/github/languages/top/Bejibun-Framework/bejibun-cache)
![NPM Downloads](https://img.shields.io/npm/d18m/%40bejibun%2Fcache)
![GitHub issues](https://img.shields.io/github/issues/Bejibun-Framework/bejibun-cache)
![GitHub](https://img.shields.io/github/license/Bejibun-Framework/bejibun-cache)
![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/Bejibun-Framework/bejibun-cache?display_name=tag&include_prereleases)

</div>

# Cache for Bejibun
Cache for Bejibun Framework.

## Usage

### Installation
Install the package.

```bash
# Using Bun
bun add @bejibun/cache

# Using Bejibun
bun ace install @bejibun/cache
```

### Configuration
The configuration file automatically executed if you are using `ace`.

Or

Add `cache.ts` inside config directory on your project if doesn't exist.

```bash
config/cache.ts
```

```ts
import App from "@bejibun/app";
import CacheDriverEnum from "@bejibun/utils/enums/CacheDriverEnum";

const config: Record<string, any> = {
    connection: "local",

    connections: {
        local: {
            driver: CacheDriverEnum.Local,
            path: App.Path.storagePath("cache") // absolute path
        },

        redis: {
            driver: CacheDriverEnum.Redis,
            host: "127.0.0.1",
            port: 6379,
            password: "",
            database: 0
        }
    }
};

export default config;
```

You can pass the value with environment variables.

### How to Use
How to use tha package.

```ts
import Cache from "@bejibun/cache";

Cache.connection();
await Cache.remember("key", () => {}, 60 /* seconds */); // any
await Cache.has("key"); // boolean
await Cache.get("key"); // any
await Cache.add("key", "Hello world", 60 /* seconds */); // boolean
await Cache.put("key", "Lorem ipsum", 60 /* seconds */); // boolean
await Cache.forget("key"); // void
await Cache.increment("key"); // number
await Cache.decrement("key"); // number
await Cache.incrementBy("key", 5); // number
await Cache.decrementBy("key", 5); // number
```

## ☕ Support / Donate

If you find this project helpful and want to support it:

[![Donate](https://img.shields.io/badge/Donate-Support%20Me-orange?style=for-the-badge)](https://donate.bejibun.com)

Or you can buy this `$BJBN (Bejibun)` tokens [here](https://pump.fun/coin/CQhbNnCGKfDaKXt8uE61i5DrBYJV7NPsCDD9vQgypump).