GithubHelp home page GithubHelp logo

flavrhub / angular-universal-express-cache-engine Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 3.0 1001 KB

Angular Universal Express Cache Engine

License: MIT License

TypeScript 100.00%
express-engine angular cache

angular-universal-express-cache-engine's Introduction

Angular Universal Express Cache Engine

Express enging that catches the request by the url so that the request doesn't have to go through all the Angular Universal each time. Really handy to cache static pages.

Uses the cache-manager package for catching, which can be used with a bunch of different engines, checkout it documentation for futher information.

Instalation

Just place the express-engine.ts file in your project and in your server.ts replace:

server.engine('html', ngExpressEngine({
    bootstrap: AppServerModule,
 }));

with

server.engine('html', ngFlavrHubExpressEngine({
    bootstrap: AppServerModule,
    routeCaches
}));

And at the beginning of it specify the routes you want to catch:

const routeCaches = [
    {path: '/', ttl: 86400},
    {path: '/explore-recipes', ttl: 86400, useQueryParams: true}
];

Routes configuration

Each route configuration implements the following interface:

export interface RouteCache {
  path: string;
  useQueryParams?: boolean;
  ttl?: number;

  isCacheableValue?(path: any, req: Request): boolean;
}
  • path: The path you want to cache starting with /, for example for the home page will be /
  • useQueryParams: Whether the query params of the url should be taken in account on catching. Default: false.
  • ttl: Time to live in cache in seconds. Default: 60 seconds.
  • isCacheableValue: A function that decide if a value is cacheable on the fly

Results

Before catching

Before catching

After catching

After catching

angular-universal-express-cache-engine's People

Contributors

sbarbat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

angular-universal-express-cache-engine's Issues

The "path" argument must be of type string. Received undefined

I am trying your implementation but I am getting The "path" argument must be of type string. Received undefined when I refresh localhost, not sure why. I'm still investigating...

One change on my end, I cannot use import { ɵCommonEngine as CommonEngine } from '@nguniversal/common/​engine'; because it causes Cannot find module '@nguniversal/common/​engine' or its corresponding type declarations.
This import { CommonEngine } from '@nguniversal/common/engine'; works, but not sure if that's good to go.

Use Redis instead

How can i use Redis for caching instead of node cache,
Thanks for your work.

Angular universal so slow

Hi, I was doing some proofs of concept with your implementation, since I have very high waiting times in my project, it is an e-commerce and this is affecting the user experience. In my project, I have several routes and I have a question about what this implementation covers:
In the case of routes with path params, how are they defined?
Do I have to define all the routes of my application to be able to cache them?

As extra data, I have deployed the application in iis 7 with iis node. the classic example that you find on the internet to deploy angular universal with iis

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.