Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 4    Views: 46

frontrunner_tech
Code is Art
Profile
Posts: 20
Reg: Apr 04, 2011
Dickinson
2,850
08/24/12 04:01 PM (11 years ago)

Menu Simple - Disable Cache

Is there a way to disable caching on the menu plugin that I missed? I've modified the core to do what I needed it to do, but I'd rather avoid that if there is a setting somewhere. The menu is built programmatically and linked to Custom URL screens which are created programmatically. In the Custom URL screen, there is an option to delete the item and when it's deleted, it is also deleted from the menu. The problem is, when hitting the back button after deleting the item, the cached menu is shown. You have to refresh the screen to see the item removed. I need it to get the JSON each time. I commented out a few if statements, starting around line 220 (if(!didLoadData)), disabling the cache (and possibly breaking something else, but not problems yet!).
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
08/24/12 10:49 PM (11 years ago)
There's always a way, just a matter of figuring out the best approach. Good to see you "tried something" - it's a start. OK, because you're removing an item from the list on the previous screen, it makes sense that you would want to "refresh it." I can think of a few different ways to do this. I think the easiest would be to... a) Delete the previously cached file every time the screen loads. Do this with the super useful BT_fileManager class. b) Ignore the self.didInit property in the viewWillAppear method to force a new download. Inside the viewWillAppear (wich runs everytime the screen displays, even on "back" presses) find remove the previously cached file, just above this line: if(self.didInit == 0){ add... [BT_fileManager deleteFile:self.saveAsFileName]; Then, to force the re-download, ignore the self.didInit == 0 logic by commenting out [self setDidInit:1] on line 100. The whole thing becomes... [BT_fileManager deleteFile:self.saveAsFileName]; if(self.didInit == 0){ [self performSelector:(@selector(loadData)) withObject:nil afterDelay:0.1]; //[self setDidInit:1]; } Bet that does the trick. I can think of a few other ways to do the same thing but that seems the easiest.
 
frontrunner_tech
Code is Art
Profile
Posts: 20
Reg: Apr 04, 2011
Dickinson
2,850
like
08/24/12 11:18 PM (11 years ago)
Okay, well first of all, I'm glad I didn't tear into everything and then later found out I overlooked a setting that would disable caching. Sorry, forgot to mention: Android. That's okay, I'll have to do the same thing in iOS, so this will save some time, now I know just where to look and what to do! It seems to be working fine (on Android), but I'm not sure if it's the cleanest way. With your solution, is that going to disable caching for the entire app? It's fine if our screens & data are cached, except for the menus. And really, just the dynamic menus, the ones that use the JSON response from our webservice. Here's the onStart method and the changes: //onStart @Override protected void onStart() { BT_debugger.showIt(activityName + ":onStart"); super.onStart(); //make sure data adapter is set... if(childItemAdapter == null){ childItemAdapter = new ChildItemAdapter(); } //***DISABLED CACHING //***WHEN ITEM IS DELETED AND BACK BUTTON IS PRESSED, //***MENU SHOULD REFLECT CHANGES WITHOUT REFRESH //ignore this if we already created the screen... //if(!didLoadData){ //if(saveAsFileName.length() > 1){ //check cache... //String parseData = ""; //if(BT_fileManager.doesCachedFileExist(saveAsFileName)){ // BT_debugger.showIt(activityName + ":onStart using cached screen data"); // parseData = BT_fileManager.readTextFileFromCache(saveAsFileName); // parseScreenData(parseData); //}else{ //get data from URL if we have one... if(this.dataURL.length() > 1){ BT_debugger.showIt(activityName + ":onStart downloading screen data from URL"); refreshScreenData(); }else{ //parse with "empty" data... BT_debugger.showIt(activityName + ":onStart using data from app's configuration file"); parseScreenData(""); } //} //}//saveAsFileName //}//did load data }
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
08/24/12 11:23 PM (11 years ago)
This method only affects that screen. Each screen that uses a dataURL caches a plain text file for THAT screen only. Deleting that screens cached data file won't affect the other screens.
 
juk
Aspiring developer
Profile
Posts: 29
Reg: Feb 16, 2014
York, UK
890
like
01/05/15 02:48 PM (9 years ago)
Hi all. Happy New Year. If anyone's still watching this post, I wonder if you could help. I tried David's method in my iOS app as I need Menu Simple screens not to get cached, i.e. I changed to the following in viewWillAppear: ------- [BT_fileManager deleteFile:self.saveAsFileName]; if(self.didInit == 0){ [self performSelector:(@selector(loadData)) withObject:nil afterDelay:0.1]; //[self setDidInit:1]; } ------- But it fails with an uncaught exception at: filePath = [filePath stringByAppendingString:fileName]; I think it might be because (judging a debug) fileName is null. Could anyone advice me on this or other methods to disable the cache? Thanks James
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.