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

Clear cache on signout #20477

Merged
merged 6 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,8 @@ PODS:
- Firebase/Performance (= 8.8.0)
- React-Core
- RNFBApp
- RNFS (2.20.0):
- React-Core
- RNGestureHandler (2.9.0):
- React-Core
- RNLocalize (2.2.6):
Expand Down Expand Up @@ -809,6 +811,7 @@ DEPENDENCIES:
- "RNFBApp (from `../node_modules/@react-native-firebase/app`)"
- "RNFBCrashlytics (from `../node_modules/@react-native-firebase/crashlytics`)"
- "RNFBPerf (from `../node_modules/@react-native-firebase/perf`)"
- RNFS (from `../node_modules/react-native-fs`)
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
- RNLocalize (from `../node_modules/react-native-localize`)
- RNPermissions (from `../node_modules/react-native-permissions`)
Expand Down Expand Up @@ -999,6 +1002,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/@react-native-firebase/crashlytics"
RNFBPerf:
:path: "../node_modules/@react-native-firebase/perf"
RNFS:
:path: "../node_modules/react-native-fs"
RNGestureHandler:
:path: "../node_modules/react-native-gesture-handler"
RNLocalize:
Expand Down Expand Up @@ -1120,6 +1125,7 @@ SPEC CHECKSUMS:
RNFBApp: 729c0666395b1953198dc4a1ec6deb8fbe1c302e
RNFBCrashlytics: 2061ca863e8e2fa1aae9b12477d7dfa8e88ca0f9
RNFBPerf: 389914cda4000fe0d996a752532a591132cbf3f9
RNFS: 4ac0f0ea233904cb798630b3c077808c06931688
RNGestureHandler: 071d7a9ad81e8b83fe7663b303d132406a7d8f39
RNLocalize: d4b8af4e442d4bcca54e68fc687a2129b4d71a81
RNPermissions: dcdb7b99796bbeda6975a6e79ad519c41b251b1c
Expand Down
6 changes: 6 additions & 0 deletions jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ jest.spyOn(console, 'debug').mockImplementation((...params) => {
// eslint-disable-next-line no-console
console.log('DEBUG', ...params);
});

// This mock is required for mocking file systems when running tests
jest.mock('react-native-fs', () => ({
unlink: jest.fn(() => new Promise((res) => res())),
CachesDirectoryPath: jest.fn(),
}));
38 changes: 38 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"react-native-device-info": "^10.3.0",
"react-native-document-picker": "^8.0.0",
"react-native-fast-image": "^8.6.3",
"react-native-fs": "^2.20.0",
"react-native-gesture-handler": "2.9.0",
"react-native-google-places-autocomplete": "git+https://github.com/Expensify/react-native-google-places-autocomplete.git#6f436a06a3018cb49750bb110b89df75f6a865d5",
"react-native-haptic-feedback": "^1.13.0",
Expand Down
5 changes: 5 additions & 0 deletions src/libs/actions/Session/clearCache/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function clearStorage() {
return new Promise((res) => res());
}

export default clearStorage;
8 changes: 8 additions & 0 deletions src/libs/actions/Session/clearCache/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {CachesDirectoryPath, unlink} from 'react-native-fs';

function clearStorage() {
// `unlink` is used to delete the caches directory
return unlink(CachesDirectoryPath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better if we add a comment here to explain what unlink does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

}

export default clearStorage;
5 changes: 4 additions & 1 deletion src/libs/actions/Session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Onyx from 'react-native-onyx';
import _ from 'underscore';
import lodashGet from 'lodash/get';
import {Linking} from 'react-native';
import clearCache from './clearCache';
import ONYXKEYS from '../../../ONYXKEYS';
import redirectToSignIn from '../SignInRedirect';
import CONFIG from '../../../CONFIG';
Expand Down Expand Up @@ -72,7 +73,9 @@ function signOut() {
partnerPassword: CONFIG.EXPENSIFY.PARTNER_PASSWORD,
shouldRetry: false,
});

clearCache().then(() => {
Log.info('Cleared all chache data', true, {}, true);
});
Timing.clearData();
}

Expand Down