Permalink
Browse files

Rename simple-cache-provider to react-cache (#13755)

  • Loading branch information...
acdlite committed Oct 1, 2018
1 parent c521264 commit ce96e2df4d9f3367e07f25153e5282d4c0869bac
@@ -26,7 +26,7 @@ Set [the `enableSuspense` flag](https://github.com/facebook/react/blob/d79238f1e
# 1: Build react from source
cd /path/to/react
yarn
yarn build dom-client,core,simple-cache-provider,schedule --type=NODE
yarn build dom-client,core,react-cache,schedule --type=NODE
# 2: Install fixture dependencies
cd fixtures/unstable-async/suspense/
@@ -4,7 +4,7 @@ import {
unstable_trace as trace,
unstable_wrap as wrap,
} from 'scheduler/tracing';
import {createResource} from 'simple-cache-provider';
import {createResource} from 'react-cache';
import {cache} from '../cache';
import Spinner from './Spinner';
import ContributorListPage from './ContributorListPage';
@@ -1,5 +1,5 @@
import React, {Fragment} from 'react';
import {createResource} from 'simple-cache-provider';
import {createResource} from 'react-cache';
import {cache} from '../cache';
import Spinner from './Spinner';
import {fetchCoreContributorListJSON} from '../api';
@@ -1,5 +1,5 @@
import React, {Placeholder} from 'react';
import {createResource} from 'simple-cache-provider';
import {createResource} from 'react-cache';
import Spinner from './Spinner';
import {cache} from '../cache';
import {fetchUserProfileJSON, fetchUserRepositoriesListJSON} from '../api';
@@ -18,7 +18,7 @@ There are also known bugs and inefficiencies in master so **don't use this fixtu
# 1: Build react from source
cd /path/to/react
yarn
yarn build dom-client,core,simple-cache-provider,scheduler --type=NODE
yarn build dom-client,core,react-cache,scheduler --type=NODE
# 2: Install fixture dependencies
cd fixtures/unstable-async/time-slicing/
@@ -8,7 +8,7 @@ This utility should be used for subscriptions to a single value that are typical

Other cases have **better long-term solutions**:
* Redux/Flux stores should use the [context API](https://reactjs.org/docs/context.html) instead.
* I/O subscriptions (e.g. notifications) that update infrequently should use [`simple-cache-provider`](https://github.com/facebook/react/blob/master/packages/simple-cache-provider/README.md) instead.
* I/O subscriptions (e.g. notifications) that update infrequently should use [`react-cache`](https://github.com/facebook/react/blob/master/packages/react-cache/README.md) instead.
* Complex libraries like Relay/Apollo should manage subscriptions manually with the same techniques which this library uses under the hood (as referenced [here](https://gist.github.com/bvaughn/d569177d70b50b58bff69c3c4a5353f3)) in a way that is most optimized for their library usage.

## Limitations in async mode
@@ -1,4 +1,4 @@
# simple-cache-provider
# react-cache

A basic cache for React applications. It also serves as a reference for more
advanced caching implementations.
@@ -9,4 +9,4 @@

'use strict';

export * from './src/SimpleCacheProvider';
export * from './src/ReactCache';
@@ -0,0 +1,7 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./cjs/react-cache.production.min.js');
} else {
module.exports = require('./cjs/react-cache.development.js');
}
@@ -1,7 +1,7 @@
{
"name": "simple-cache-provider",
"name": "react-cache",
"description": "A basic cache for React applications",
"version": "0.10.0",
"version": "2.0.0-alpha.0",
"repository": "facebook/react",
"files": [
"LICENSE",
@@ -400,4 +400,4 @@ export function createResource<V, K, H: primitive>(

// Global cache has no eviction policy (except for, ya know, a browser refresh).
const globalCache = createCache(noop);
export const SimpleCache = React.createContext(globalCache);
export const ReactCache = React.createContext(globalCache);
@@ -9,16 +9,16 @@

'use strict';

let SimpleCacheProvider;
let ReactCache;

describe('SimpleCacheProvider', () => {
describe('ReactCache', () => {
beforeEach(() => {
jest.resetModules();
SimpleCacheProvider = require('simple-cache-provider');
ReactCache = require('react-cache');
});

it('throws a promise if the requested value is not in the cache', async () => {
const {createCache, createResource} = SimpleCacheProvider;
const {createCache, createResource} = ReactCache;

function loadUpperCase(text) {
return Promise.resolve(text.toUpperCase());
@@ -39,7 +39,7 @@ describe('SimpleCacheProvider', () => {
});

it('throws an error on the subsequent read if the promise is rejected', async () => {
const {createCache, createResource} = SimpleCacheProvider;
const {createCache, createResource} = ReactCache;

let shouldFail = true;
function loadUpperCase(text) {
@@ -83,7 +83,7 @@ describe('SimpleCacheProvider', () => {
});

it('can preload data ahead of time', async () => {
const {createCache, createResource} = SimpleCacheProvider;
const {createCache, createResource} = ReactCache;

function loadUpperCase(text) {
return Promise.resolve(text.toUpperCase());
@@ -99,7 +99,7 @@ describe('SimpleCacheProvider', () => {
});

it('does not throw if preloaded promise rejects', async () => {
const {createCache, createResource} = SimpleCacheProvider;
const {createCache, createResource} = ReactCache;

function loadUpperCase(text) {
return Promise.reject(new Error('uh oh'));
@@ -115,7 +115,7 @@ describe('SimpleCacheProvider', () => {
});

it('accepts custom hash function', async () => {
const {createCache, createResource} = SimpleCacheProvider;
const {createCache, createResource} = ReactCache;

function loadSum([a, b]) {
return Promise.resolve(a + b);
@@ -138,7 +138,7 @@ describe('SimpleCacheProvider', () => {
});

it('warns if resourceType is a string or number', () => {
const {createCache} = SimpleCacheProvider;
const {createCache} = ReactCache;

spyOnDev(console, 'error');
const cache = createCache();
@@ -166,7 +166,7 @@ describe('SimpleCacheProvider', () => {
});

it('warns if non-primitive key is passed to a resource without a hash function', () => {
const {createCache, createResource} = SimpleCacheProvider;
const {createCache, createResource} = ReactCache;

spyOnDev(console, 'error');

@@ -197,7 +197,7 @@ describe('SimpleCacheProvider', () => {
});

it('stays within maximum capacity by evicting the least recently used record', async () => {
const {createCache, createResource} = SimpleCacheProvider;
const {createCache, createResource} = ReactCache;

function loadIntegerString(int) {
return Promise.resolve(int + '');
@@ -2,7 +2,7 @@ let React;
let ReactFeatureFlags;
let Fragment;
let ReactNoop;
let SimpleCacheProvider;
let ReactCache;
let Placeholder;
let StrictMode;
let ConcurrentMode;
@@ -22,17 +22,17 @@ describe('ReactSuspense', () => {
React = require('react');
Fragment = React.Fragment;
ReactNoop = require('react-noop-renderer');
SimpleCacheProvider = require('simple-cache-provider');
ReactCache = require('react-cache');
Placeholder = React.Placeholder;
StrictMode = React.StrictMode;
ConcurrentMode = React.unstable_ConcurrentMode;
lazy = React.lazy;

function invalidateCache() {
cache = SimpleCacheProvider.createCache(invalidateCache);
cache = ReactCache.createCache(invalidateCache);
}
invalidateCache();
TextResource = SimpleCacheProvider.createResource(([text, ms = 0]) => {
TextResource = ReactCache.createResource(([text, ms = 0]) => {
return new Promise((resolve, reject) =>
setTimeout(() => {
if (textResourceShouldFail) {
@@ -2172,15 +2172,15 @@ describe('Profiler', () => {
}

beforeEach(() => {
const SimpleCacheProvider = require('simple-cache-provider');
const ReactCache = require('react-cache');
function invalidateCache() {
cache = SimpleCacheProvider.createCache(invalidateCache);
cache = ReactCache.createCache(invalidateCache);
}
invalidateCache();

resourcePromise = null;

TextResource = SimpleCacheProvider.createResource(([text, ms = 0]) => {
TextResource = ReactCache.createResource(([text, ms = 0]) => {
resourcePromise = new Promise((resolve, reject) =>
setTimeout(() => {
yieldForRenderer(`Promise resolved [${text}]`);
@@ -13,7 +13,7 @@ let React;
let ReactFeatureFlags;
let ReactDOM;
let SchedulerTracing;
let SimpleCacheProvider;
let ReactCache;

function initEnvForAsyncTesting() {
// Boilerplate copied from ReactDOMRoot-test
@@ -55,7 +55,7 @@ function loadModules() {
React = require('react');
SchedulerTracing = require('scheduler/tracing');
ReactDOM = require('react-dom');
SimpleCacheProvider = require('simple-cache-provider');
ReactCache = require('react-cache');
}

describe('ProfilerDOM', () => {
@@ -82,11 +82,11 @@ describe('ProfilerDOM', () => {
onWorkStopped: () => {},
});

cache = SimpleCacheProvider.createCache(() => {});
cache = ReactCache.createCache(() => {});

resourcePromise = null;

TextResource = SimpleCacheProvider.createResource(([text, ms = 0]) => {
TextResource = ReactCache.createResource(([text, ms = 0]) => {
resourcePromise = new Promise(
SchedulerTracing.unstable_wrap((resolve, reject) => {
setTimeout(

This file was deleted.

Oops, something went wrong.
@@ -363,13 +363,13 @@ const bundles = [
externals: [],
},

/******* Simple Cache Provider (experimental) *******/
/******* React Cache (experimental) *******/
{
label: 'simple-cache-provider',
label: 'react-cache',
bundleTypes: [FB_WWW_DEV, FB_WWW_PROD, NODE_DEV, NODE_PROD],
moduleType: ISOMORPHIC,
entry: 'simple-cache-provider',
global: 'SimpleCacheProvider',
entry: 'react-cache',
global: 'ReactCache',
externals: ['react'],
},

Oops, something went wrong.

0 comments on commit ce96e2d

Please sign in to comment.