Caching

Last Update:
Preload ads on your users' devices to boost their experience! Ads will load faster when requested, and you can verify that an ad is available before displaying it.

 

 

Use the following methods to cache ads so they can be displayed later. We use CBLocationHomeScreen as our example named location.

 

[Chartboost cacheInterstitial:CBLocationHomeScreen];
[Chartboost cacheRewardedVideo:CBLocationHomeScreen];

 

Chartboost.cacheInterstitial(CBLocation.LOCATION_HOME_SCREEN);
Chartboost.cacheRewardedVideo(CBLocation.LOCATION_HOME_SCREEN);

 

Chartboost.cacheInterstitial(CBLocation.HomeScreen);
Chartboost.cacheRewardedVideo(CBLocation.HomeScreen);

 

Chartboost.getInstance().cacheInterstitial(CBLocation.HOME_SCREEN);
Chartboost.getInstance().cacheRewardedVideo(CBLocation.HOME_SCREEN); 

▲ Back to top

 

PRO TIP: Use these methods to check if an ad has been preloaded before you try to show it. If an ad isn't already cached, you should probably cache one!

 

if([Chartboost hasInterstitial:CBLocationHomeScreen] == YES) {
    [Chartboost showInterstitial:CBLocationHomeScreen];
}
else {
    [Chartboost cacheInterstitial:CBLocationHomeScreen];
}

 

if (Chartboost.hasInterstitial(CBLocation.LOCATION_HOME_SCREEN)) {
    Chartboost.showInterstitial(CBLocation.LOCATION_HOME_SCREEN);
}
else {
    Chartboost.cacheInterstitial(CBLocation.LOCATION_HOME_SCREEN);
}

 

if (Chartboost.hasInterstitial(CBLocation.HomeScreen)) {
    Chartboost.showInterstitial(CBLocation.HomeScreen);
}
else {
    Chartboost.cacheInterstitial(CBLocation.HomeScreen);
}

 

if (Chartboost.getInstance().hasInterstitial(CBLocation.HOME_SCREEN)) {
    Chartboost.getInstance().showInterstitial(CBLocation.HOME_SCREEN)
}
else {
    Chartboost.getInstance().cacheInterstitial(CBLocation.HOME_SCREEN)
}

 


 

Optional: You also can receive notification from the SDK when an ad is successfully cached by implementing these delegate methods.

 

- (void)didCacheInterstitial:(CBLocation)location
- (void)didCacheRewardedVideo:(CBLocation)location 
public void didCacheInterstitial(String location)
public void didCacheRewardedVideo(String location) 
void didCacheInterstitial(CBLocation location)
void didCacheRewardedVideo(CBLocation location) 
public static const DID_CACHE_INTERSTITIAL:String = "didCacheInterstitial";
public static const DID_CACHE_REWARDED_VIDEO:String = "didCacheRewardedVideo";

 


If the cache calls fails, a didFailToLoadInterstitial delegate method will fire. This delegate also fires if you call showInterstitial and an ad fails to display. Do NOT make cache or show calls inside didFailToLoad delegates or the universe will implode.

 

- (void)didFailToLoadInterstitial:(CBLocation)location withError:(CBLoadError)error
- (void)didFailToLoadRewardedVideo:(CBLocation)location withError:(CBLoadError)error 
public void didFailToLoadInterstitial(String location, CBImpressionError error)
public void didFailToLoadRewardedVideo(String location, CBImpressionError error) 
void didFailToLoadInterstitial(CBLocation location, CBImpressionError error)
void didFailToLoadRewardedVideo(CBLocation location, CBImpressionError error) 
Chartboost.getInstance().addDelegate(ChartboostEvent.DID_FAIL_TO_LOAD_INTERSTITIAL, function (location:String))
Chartboost.getInstance().addDelegate(ChartboostEvent.DID_FAIL_TO_LOAD_REWARDED_VIDEO, function(location:String))

 

▲ Back to top

 

PRO TIP: Chartboost SDKs automatically cache ads after they've been successfully displayed at a named location. However, it's best practice to also manually cache ads at bootup or other relevant points in your app before you need to display them.
Autocaching will not cause unnecessary network requests. Any cache calls will only send network requests if the cache is empty at a specific location.

 

Use the following SDK methods to toggle autocaching.

 

[Chartboost setAutoCacheAds:BOOLEAN];

 

Chartboost.setAutoCacheAds(boolean);

 

Chartboost.setAutoCacheAds(boolean);

 

Chartboost.getInstance().setAutoCacheAds(shouldCache:Boolean);

 

▲ Back to top

 

  • [Chartboost showInterstitial:CBLocationHomeScreen]; displays a cached interstitial if one exists. Otherwise, it will request one from the server.
  • We recommend caching for optimal performance and user experience; however, it's always a good idea to be conscious of your users' data usage.
  • Cached interstitials automatically expire after 24 hours.
  • Cache requests are asynchronous. Keep this in mind if you cache many interstitials while loading other data for your app.

▲ Back to top

 


You might also like...
  • Named locations: Show different ad campaigns at different points in your game and fine-tune your campaigns' behavior from your dashboard.