# @joebobstevedave/ngx-cache-platform-server

> Server platform implementation of ngx-cache

Latest version **8.0.0** (published 2019-11-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @joebobstevedave/ngx-cache-platform-server
pnpm add @joebobstevedave/ngx-cache-platform-server
yarn add @joebobstevedave/ngx-cache-platform-server
bun add @joebobstevedave/ngx-cache-platform-server
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 8.0.0 |
| Published | 2019-11-14 |
| First published | 2019-11-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Burak Tasci |
| Maintainers | joebobstevedave |
| Keywords | server side, platform-server, caching, cache, universal, angular |

## Links

- npm: https://www.npmjs.com/package/@joebobstevedave/ngx-cache-platform-server
- Repository: https://github.com/joebobstevedave/ngx-cache
- Homepage: https://github.com/fulls1z3/ngx-cache/tree/master/packages/@ngx-cache/platform-server#readme
- Issues: https://github.com/fulls1z3/ngx-cache/issues
- npm.io page: https://npm.io/package/@joebobstevedave/ngx-cache-platform-server

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ~1.9.0

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 8.0.0 (latest) — 2019-11-14

## README

# @ngx-cache/platform-server [![npm version](https://badge.fury.io/js/%40ngx-cache%2Fplatform-server.svg)](https://www.npmjs.com/package/@ngx-cache/platform-server) [![npm downloads](https://img.shields.io/npm/dm/%40ngx-cache%2Fplatform-server.svg)](https://www.npmjs.com/package/@ngx-cache/platform-server)

**Server platform** implementation of [ngx-cache]

[![CircleCI](https://circleci.com/gh/fulls1z3/ngx-cache.svg?style=shield)](https://circleci.com/gh/fulls1z3/ngx-cache)
[![coverage](https://codecov.io/github/fulls1z3/ngx-cache/coverage.svg?branch=master)](https://codecov.io/gh/fulls1z3/ngx-cache)
[![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
[![Angular Style Guide](https://mgechev.github.io/angular2-style-guide/images/badge.svg)](https://angular.io/styleguide)

> Please support this project by simply putting a Github star. Share this library with friends on Twitter and everywhere else you can.

#### NOTICE

> This _[7.x.x] branch_ is intented to work with `Angular v7.x.x`. If you're developing on a later release of **Angular**
> than `v7.x.x`, then you should probably choose the appropriate version of this library by visiting the _[master] branch_.

## Table of contents:

- [Prerequisites](#prerequisites)
- [Getting started](#getting-started)
  - [Installation](#installation) - [Examples](#examples) - [Related packages](#related-packages) - [Adding `@ngx-cache/platform-server` to your project (SystemJS)](#adding-systemjs)
  - [app.module configuration](#appmodule-config)
- [Credits](#credits)
- [License](#license)

## <a name="prerequisites"></a> Prerequisites

This library depends on `Angular v6.0.0`. Older versions contain outdated dependencies, might produce errors.

Also, please ensure that you are using **`Typescript v2.7.2`** or higher.

## <a name="getting-started"> Getting started

### <a name="installation"> Installation

You can install **`@ngx-cache/platform-server`** using `npm`

```
npm install @ngx-cache/platform-server --save
```

**Note**: You should have already installed [@ngx-cache/core].

**Note**: You should have also installed [@ngx-cache/fs-storage] (_which is currently the only available storage on the
server platform_).

### <a name="examples"></a> Examples

- [ng-seed/universal] is an officially maintained seed project, showcasing common patterns and best practices for **`@ngx-cache/platform-server`**.

### <a name="related-packages"></a> Related packages

The following packages may be used in conjunction with **`@ngx-cache/platform-server`**:

- [@ngx-cache/core]
- [@ngx-cache/fs-storage]

### <a name="adding-systemjs"></a> Adding `@ngx-cache/platform-server` to your project (SystemJS)

Add `map` for **`@ngx-cache/platform-server`** in your `systemjs.config`

```javascript
'@ngx-cache/platform-server': 'node_modules/@ngx-cache/platform-server/bundles/platform-server.umd.min.js'
```

### <a name="appmodule-config"></a> app.module configuration

- Import `ServerCacheModule` using the mapping `'@ngx-cache/platform-server'` and append `ServerCacheModule.forRoot({...})`
  within the imports property of **app.server.module** (_considering the app.server.module is the server module in Angular
  Universal application_).
- Import `CACHE` injection token using the mapping `'@ngx-cache/core'`, `FsCacheService` using the mapping `'@ngx-cache/platform-server'`.
- Provide `CACHE` using `FsCacheService`, by calling the [forRoot] static method using the `ServerCacheModule`.
- Import `STORAGE` injection token using the mapping `'@ngx-cache/core'`, `FsStorageService` using the mapping `'@ngx-cache/fs-storage'`.
- Provide `STORAGE` using `FsStorageService`, by calling the [forRoot] static method using the `ServerCacheModule`.
- Import `FsStorageLoader` and `fsStorageFactory` using the mapping `'@ngx-cache/fs-storage'`.
- Provide `FsStorageLoader` using `fsStorageFactory`, by calling the [forRoot] static method using the `ServerCacheModule`.
- Pass `CacheService` together with `ApplicationRef` and `TransferState` to the implementation of `bootstrapFactory` method
  below.

#### app.server.module.ts

```TypeScript
...
import { CacheService, CACHE, STORAGE } from '@ngx-cache/core';
import { ServerCacheModule, FsCacheService } from '@ngx-cache/platform-server';
import { fsStorageFactory, FsStorageLoader, FsStorageService } from '@ngx-cache/fs-storage';

...


export function bootstrapFactory(appRef: ApplicationRef,
                                 transferState: TransferState,
                                 cache: CacheService): () => Subscription {
  return () => appRef.isStable
    .filter(stable => stable)
    .first()
    .subscribe(() => {
      transferState.set<any>(makeStateKey(cache.key), JSON.stringify(cache.dehydrate()));
    });
}


@NgModule({
  declarations: [
    AppComponent,
    ...
  ],
  ...
  imports: [
    ...
    ServerCacheModule.forRoot([
      {
        provide: CACHE,
        useClass: FsCacheService
      },
      {
        provide: STORAGE,
        useClass: FsStorageService
      },
      {
        provide: FsStorageLoader,
        useFactory: (fsStorageFactory)
      }
    ]),
  ],
  ...
  providers: [
    {
      provide: APP_BOOTSTRAP_LISTENER,
      useFactory: (bootstrapFactory),
      multi: true,
      deps: [
        ApplicationRef,
        TransferState,
        CacheService
      ]
    }
  ],
  bootstrap: [AppComponent]
})
export class AppServerModule {
}
```

> :+1: Yeah! **`@ngx-cache/platform-server`** will now provide **server platform** implementation to [@ngx-cache/core].

## <a name="credits"></a> Credits

- [universal-starter](https://github.com/angular/universal-starter): Angular 2 Universal starter kit by @AngularClass

## <a name="license"></a> License

The MIT License (MIT)

Copyright (c) 2018 [Burak Tasci]

[master]: https://github.com/fulls1z3/ngx-cache/core/tree/master
[7.x.x]: https://github.com/fulls1z3/ngx-cache/core/tree/7.x.x
[ngx-cache]: https://github.com/fulls1z3/ngx-cache
[ng-seed/universal]: https://github.com/ng-seed/universal
[@ngx-cache/core]: https://github.com/fulls1z3/ngx-cache/tree/master/packages/@ngx-cache/core
[@ngx-cache/fs-storage]: https://github.com/fulls1z3/ngx-cache/tree/master/packages/@ngx-cache/fs-storage
[forroot]: https://angular.io/docs/ts/latest/guide/ngmodule.html#!#core-for-root
[burak tasci]: https://github.com/fulls1z3

---
_Source: https://npm.io/package/@joebobstevedave/ngx-cache-platform-server · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
