Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cache] Allow caching behaviour to be configurable #162

Merged
merged 1 commit into from
Mar 9, 2019

Conversation

JorgenEvens
Copy link
Member

@JorgenEvens JorgenEvens commented Mar 9, 2019

This PR makes the default caching behavior configurable by exposing the default implementation as a class which takes sourceTTL and sourceSize as options.

import Avatar, { Cache, ConfigProvider } from 'react-avatar';

const cache = new Cache({

    // Keep cached source failures for up to 7 days
    sourceTTL: 7 * 24 * 3600 * 1000,

    // Keep a maximum of 20 entries in the source cache
    sourceSize: 20
});

// Apply cache globally
<ConfigProvider cache={cache}>
    <YourApp>
        ...
        <Avatar name="Wim Mostmans" />
        ...
    </YourApp>
</ConfigProvider>

// For specific instances
<Avatar name="Wim Mostmans" cache={cache} />

Resolves #161

@JorgenEvens JorgenEvens self-assigned this Mar 9, 2019
@JorgenEvens JorgenEvens added this to the 3.6.0 milestone Mar 9, 2019
@JorgenEvens JorgenEvens merged commit 7066a1e into master Mar 9, 2019
@JorgenEvens JorgenEvens deleted the feature/configurable-cache branch March 9, 2019 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant