🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

@reignmodule/contentful-utils

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@reignmodule/contentful-utils

### Get entries by field value

latest
Source
npmnpm
Version
1.6.3
Version published
Maintainers
2
Created
Source

Content ful cache

Get entries by field value

Sample:

import { ContentfulCache } from '@reignmodule/contentful-utils/contentful-cache'

const client = contentful.createClient()

const contentfulCache = new ContentfulCache({ client, fieldIndexable: ['slug'] });

// Get entries by field value
for await (const entry of contentfulCache.getEntriesByField('slug', ['/home', '/article/123', '/article/456'])) {
    // ... do something with entry. Time 500ms
}

// Second time, we can get the entries from cache
for await (const entry of contentfulCache.getEntriesByField('slug', ['/home', '/article/123', '/article/456'])) {
    // ... do something with entry. Time 10ms
}

Get entries by query

Sample:

import { ContentfulCache } from '@reignmodule/contentful-utils/contentful-cache'

const client = contentful.createClient()

const contentfulCache = new ContentfulCache({ client, fieldIndexable: ['slug'] });

// Get entries by field value
for await (const entry of contentfulCache.getEntries({ content_type: 'articles', 'fields.type[in]': 'vip' })) {
    // ... do something with entry. Time 500ms
}

Get all entries as async iterable

Transform the get entries method to an async generator.

Example:

import { createPaginateItems } from '@reignmodule/contentful-utils/paginate-items'

const client = contentful.createClient()

const paginateItems = createPaginateItems(client.getEntries);

// Get all entries
for await (const entries of paginateItems()) {
    // ... do something with entry
}

Global configuration

You can use the CONTENTFUL_CACHE_DEFAULT_TTL environment to set the default ttl for the cache. The default is 20 minutes and the format is ${number} ${Unit}

Unit can be seconds, minutes, hours, days. Look the full list of units here: ms/index.ts#L9-L40

FAQs

Package last updated on 17 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts