@@ -28,6 +28,7 @@ class ServerInterface {
2828 this . ServerURL = "https://musicblocks.sugarlabs.org/planet-server/index.php" ;
2929 this . ConnectionFailureData = { success : false , error : "ERROR_CONNECTION_FAILURE" } ;
3030 this . APIKey = "3f2d3a4c-c7a4-4c3c-892e-ac43784f7381" ;
31+ this . disablePlanetCache = this . shouldDisablePlanetCache ( ) ;
3132
3233 // Initialize RequestManager for rate limiting and retry logic
3334 this . requestManager = new RequestManager ( {
@@ -48,6 +49,20 @@ class ServerInterface {
4849 this . cacheInitialized = false ;
4950 }
5051
52+ /**
53+ * Determines whether Planet caching should be disabled.
54+ * @returns {boolean }
55+ */
56+ shouldDisablePlanetCache ( ) {
57+ const runtimeEnv = window . MB_ENV ;
58+
59+ if ( runtimeEnv === "production" ) {
60+ return false ;
61+ }
62+
63+ return true ;
64+ }
65+
5166 /**
5267 * Initializes the cache manager
5368 * @returns {Promise<boolean> }
@@ -149,23 +164,24 @@ class ServerInterface {
149164 * Gets project details with caching support
150165 */
151166 async getProjectDetails ( ProjectID , callback ) {
152- // Try cache first
153- await this . initCache ( ) ;
154- const cached = await this . cacheManager . getMetadata ( ProjectID ) ;
155-
156- if ( cached ) {
157- // eslint-disable-next-line no-console
158- console . debug ( "[ServerInterface] Returning cached metadata for:" , ProjectID ) ;
159- callback ( { success : true , data : cached } ) ;
160- return ;
167+ if ( ! this . disablePlanetCache ) {
168+ // Try cache first
169+ await this . initCache ( ) ;
170+ const cached = await this . cacheManager . getMetadata ( ProjectID ) ;
171+
172+ if ( cached ) {
173+ // eslint-disable-next-line no-console
174+ console . debug ( "[ServerInterface] Returning cached metadata for:" , ProjectID ) ;
175+ callback ( { success : true , data : cached } ) ;
176+ return ;
177+ }
161178 }
162-
163179 // Fetch from server
164180 const obj = { action : "getProjectDetails" , ProjectID : ProjectID } ;
165181
166182 this . throttledRequest ( obj , async result => {
167183 // Cache successful responses
168- if ( result && result . success && result . data ) {
184+ if ( ! this . disablePlanetCache && result && result . success && result . data ) {
169185 await this . cacheManager . cacheMetadata ( ProjectID , result . data ) ;
170186 }
171187 callback ( result ) ;
@@ -190,23 +206,24 @@ class ServerInterface {
190206 * Downloads full project data with caching support
191207 */
192208 async downloadProject ( ProjectID , callback ) {
193- // Try cache first
194- await this . initCache ( ) ;
195- const cached = await this . cacheManager . getProject ( ProjectID ) ;
196-
197- if ( cached ) {
198- // eslint-disable-next-line no-console
199- console . debug ( "[ServerInterface] Returning cached project:" , ProjectID ) ;
200- callback ( { success : true , data : cached } ) ;
201- return ;
209+ if ( ! this . disablePlanetCache ) {
210+ // Try cache first
211+ await this . initCache ( ) ;
212+ const cached = await this . cacheManager . getProject ( ProjectID ) ;
213+
214+ if ( cached ) {
215+ // eslint-disable-next-line no-console
216+ console . debug ( "[ServerInterface] Returning cached project:" , ProjectID ) ;
217+ callback ( { success : true , data : cached } ) ;
218+ return ;
219+ }
202220 }
203-
204221 // Fetch from server
205222 const obj = { action : "downloadProject" , ProjectID : ProjectID } ;
206223
207224 this . throttledRequest ( obj , async result => {
208225 // Cache successful responses
209- if ( result && result . success && result . data ) {
226+ if ( ! this . disablePlanetCache && result && result . success && result . data ) {
210227 await this . cacheManager . cacheProject ( ProjectID , result . data ) ;
211228 }
212229 callback ( result ) ;
@@ -271,8 +288,14 @@ class ServerInterface {
271288 * Initializes the server interface
272289 */
273290 async init ( ) {
274- await this . initCache ( ) ;
291+ if ( ! this . disablePlanetCache ) {
292+ await this . initCache ( ) ;
293+ }
275294 // eslint-disable-next-line no-console
276- console . debug ( "[ServerInterface] Initialized with rate limiting and caching" ) ;
295+ console . debug (
296+ `[ServerInterface] Initialized with rate limiting and ${
297+ this . disablePlanetCache ? "cache disabled (dev mode)" : "caching"
298+ } `
299+ ) ;
277300 }
278301}
0 commit comments