
Product
Introducing PHP and Composer Support in Socket
Socket now supports PHP with full Composer and Packagist integration, enabling developers to search packages, generate SBOMs, and protect their PHP dependencies from supply chain threats.
redux-persist-expire
Advanced tools
Expiring transformer for redux-persist – Create expiring storage for your Redux stores
npm install redux-persist-expire
Create a transform using expireReducer(reducerKey, config) where reducerKey is the reducer to which expiry is to be applied and configuration can be used to configure expire behavior.
const { persistReducer, persistStore } = require('redux-persist');
// Import the transformer creator
const expireReducer = require('redux-persist-expire');
// Create persisted reducers using redux-persist
const persistedReducers = persistReducer({
transforms: [
// Create a transformer by passing the reducer key and configuration. Values
// shown below are the available configurations with default values
expireReducer('preference', {
// (Optional) Key to be used for the time relative to which store is to be expired
persistedAtKey: '__persisted_at',
// (Required) Seconds after which store will be expired
expireSeconds: null,
// (Optional) State to be used for resetting e.g. provide initial reducer state
expiredState: {},
// (Optional) Use it if you don't want to manually set the time in the reducer i.e. at `persistedAtKey`
// and want the store to be automatically expired if the record is not updated in the `expireSeconds` time
autoExpire: false
})
// You can add more `expireReducer` calls here for different reducers
// that you may want to expire
]
},
rootReducer,
);
export const store = createStore(persistedReducers);
export const persist = persistStore(store);
Here is the configuration for the common usecases
Expire the item in store if it has not been updated for the past
nseconds
// Reset `preference` key to empty object if it has not been updated for the past hour
expireReducer('preference', {
expireSeconds: 3600
})
Reset an item to empty array after it has not been updated for the past 30 minutes
// Reset `preference` key to given defaults if it has not been updated for the past hour
expireReducer('preference', {
expireSeconds: 1800,
expiredState: {
viewType: 'list',
token: ''
}
})
Expire the item in store after 30 minutes of loading it
// Reset `users` key to empty array if it had been loaded 30 minutes ago
expireReducer('users', {
persistedAtKey: 'loadedAt',
expireSeconds: 1800,
expiredState: [] // Reset to empty array after expiry
})
// Note that in this case, you have to manually set the `loadedAt` in
// this case e.g. your reducer might look like this
...
case USERS_LOADED:
return {
loadedAt: moment(), // or use (new Date()).toJSON()
users: payload
};
...
Feel free to open an issue if you need help with some specific usecase.
MIT © Kamran Ahmed
FAQs
Create expiring storage for your Redux stores
We found that redux-persist-expire demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Product
Socket now supports PHP with full Composer and Packagist integration, enabling developers to search packages, generate SBOMs, and protect their PHP dependencies from supply chain threats.

Security News
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.

Research
/Security News
Chrome extension CL Suite by @CLMasters neutralizes 2FA for Facebook and Meta Business accounts while exfiltrating Business Manager contact and analytics data.