UNPKG

1.89 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var RedisQueryResultCache_1 = require("./RedisQueryResultCache");
4var DbQueryResultCache_1 = require("./DbQueryResultCache");
5/**
6 * Caches query result into Redis database.
7 */
8var QueryResultCacheFactory = /** @class */ (function () {
9 // -------------------------------------------------------------------------
10 // Constructor
11 // -------------------------------------------------------------------------
12 function QueryResultCacheFactory(connection) {
13 this.connection = connection;
14 }
15 // -------------------------------------------------------------------------
16 // Public Methods
17 // -------------------------------------------------------------------------
18 /**
19 * Creates a new query result cache based on connection options.
20 */
21 QueryResultCacheFactory.prototype.create = function () {
22 if (!this.connection.options.cache)
23 throw new Error("To use cache you need to enable it in connection options by setting cache: true or providing some caching options. Example: { host: ..., username: ..., cache: true }");
24 if (this.connection.options.cache.type === "redis")
25 return new RedisQueryResultCache_1.RedisQueryResultCache(this.connection, "redis");
26 if (this.connection.options.cache.type === "ioredis")
27 return new RedisQueryResultCache_1.RedisQueryResultCache(this.connection, "ioredis");
28 if (this.connection.options.cache.type === "ioredis/cluster")
29 return new RedisQueryResultCache_1.RedisQueryResultCache(this.connection, "ioredis/cluster");
30 return new DbQueryResultCache_1.DbQueryResultCache(this.connection);
31 };
32 return QueryResultCacheFactory;
33}());
34exports.QueryResultCacheFactory = QueryResultCacheFactory;
35
36//# sourceMappingURL=QueryResultCacheFactory.js.map