1717// @flow -disable-next
1818const Parse = require ( 'parse/node' ) . Parse ;
1919import { StorageAdapter } from '../Adapters/Storage/StorageAdapter' ;
20+ import SchemaCache from '../Adapters/Cache/SchemaCache' ;
2021import DatabaseController from './DatabaseController' ;
2122import Config from '../Config' ;
2223// @flow -disable-next
@@ -682,15 +683,13 @@ const typeToString = (type: SchemaField | string): string => {
682683export default class SchemaController {
683684 _dbAdapter : StorageAdapter ;
684685 schemaData : { [ string ] : Schema } ;
685- _cache: any ;
686686 reloadDataPromise: ?Promise < any > ;
687687 protectedFields: any ;
688688 userIdRegEx: RegExp ;
689689
690- constructor ( databaseAdapter : StorageAdapter , singleSchemaCache : Object ) {
690+ constructor ( databaseAdapter : StorageAdapter ) {
691691 this . _dbAdapter = databaseAdapter ;
692- this . _cache = singleSchemaCache ;
693- this . schemaData = new SchemaData ( this . _cache . allClasses || [ ] , this . protectedFields ) ;
692+ this . schemaData = new SchemaData ( SchemaCache . get ( ) , this . protectedFields ) ;
694693 this . protectedFields = Config . get ( Parse . applicationId ) . protectedFields ;
695694
696695 const customIds = Config . get ( Parse . applicationId ) . allowCustomObjectId ;
@@ -729,8 +728,9 @@ export default class SchemaController {
729728 if ( options . clearCache ) {
730729 return this . setAllClasses ( ) ;
731730 }
732- if ( this . _cache . allClasses && this . _cache . allClasses . length ) {
733- return Promise . resolve ( this . _cache . allClasses ) ;
731+ const cached = SchemaCache . get ( ) ;
732+ if ( cached && cached . length ) {
733+ return Promise . resolve ( cached ) ;
734734 }
735735 return this . setAllClasses ( ) ;
736736 }
@@ -740,7 +740,7 @@ export default class SchemaController {
740740 . getAllClasses ( )
741741 . then ( allSchemas => allSchemas . map ( injectDefaultSchema ) )
742742 . then ( allSchemas => {
743- this . _cache . allClasses = allSchemas ;
743+ SchemaCache . put ( allSchemas ) ;
744744 return allSchemas ;
745745 } ) ;
746746 }
@@ -751,7 +751,7 @@ export default class SchemaController {
751751 options : LoadSchemaOptions = { clearCache : false }
752752 ) : Promise < Schema > {
753753 if ( options . clearCache ) {
754- delete this . _cache . allClasses ;
754+ SchemaCache . clear ( ) ;
755755 }
756756 if ( allowVolatileClasses && volatileClasses . indexOf ( className ) > - 1 ) {
757757 const data = this . schemaData [ className ] ;
@@ -762,7 +762,7 @@ export default class SchemaController {
762762 indexes : data . indexes ,
763763 } ) ;
764764 }
765- const cached = ( this . _cache . allClasses || [ ] ) . find ( schema => schema . className === className ) ;
765+ const cached = SchemaCache . get ( ) . find ( schema => schema . className === className ) ;
766766 if ( cached && ! options . clearCache ) {
767767 return Promise . resolve ( cached ) ;
768768 }
@@ -1050,7 +1050,7 @@ export default class SchemaController {
10501050 }
10511051 validateCLP ( perms , newSchema , this . userIdRegEx ) ;
10521052 await this . _dbAdapter . setClassLevelPermissions ( className , perms ) ;
1053- const cached = ( this . _cache . allClasses || [ ] ) . find ( schema => schema . className === className ) ;
1053+ const cached = SchemaCache . get ( ) . find ( schema => schema . className === className ) ;
10541054 if ( cached ) {
10551055 cached . classLevelPermissions = perms ;
10561056 }
@@ -1202,7 +1202,7 @@ export default class SchemaController {
12021202 } ) ;
12031203 } )
12041204 . then ( ( ) => {
1205- delete this . _cache . allClasses ;
1205+ SchemaCache . clear ( ) ;
12061206 } ) ;
12071207 }
12081208
@@ -1412,20 +1412,12 @@ export default class SchemaController {
14121412 }
14131413}
14141414
1415- const singleSchemaCache = { } ;
1416-
14171415// Returns a promise for a new Schema.
14181416const load = ( dbAdapter : StorageAdapter , options : any ) : Promise < SchemaController > => {
1419- const schema = new SchemaController ( dbAdapter , singleSchemaCache ) ;
1417+ const schema = new SchemaController ( dbAdapter ) ;
14201418 return schema . reloadData ( options ) . then ( ( ) => schema ) ;
14211419} ;
14221420
1423- const clearSingleSchemaCache = ( ) => {
1424- delete singleSchemaCache . allClasses ;
1425- } ;
1426-
1427- const getSingleSchemaCache = ( ) => singleSchemaCache . allClasses ;
1428-
14291421// Builds a new schema (in schema API response format) out of an
14301422// existing mongo schema + a schemas API put request. This response
14311423// does not include the default fields, as it is intended to be passed
@@ -1585,8 +1577,6 @@ function getObjectType(obj): ?(SchemaField | string) {
15851577
15861578export {
15871579 load ,
1588- clearSingleSchemaCache ,
1589- getSingleSchemaCache ,
15901580 classNameIsValid ,
15911581 fieldNameIsValid ,
15921582 invalidClassNameMessage ,
0 commit comments