Skip to main content

Ad Caching

GFP SDK supports disk caching for ads starting from version 8.12.0. This significantly reduces ad loading time, especially improving user experience when applied to splash ads that run in cold start environments. The disk caching targets include not only simple ad responses but also resources such as images and videos used in ads to minimize loading delays.

info
  • In internal testing, the average reduction in ad loading time is approximately 71.4%.
  • As of version 8.12.0, the disk caching feature can only be applied to S2S Native ads.

Implementation

Disk caching can be applied in two main ways as shown below, and you can choose one method to apply.

  1. Adding options to GfpAdLoader
  2. Applying custom implementation through GfpAdCacheManager

For most cases including splash ads, method 1 is sufficient and can be applied more simply than method 2.


1. Adding Options to GfpAdLoader

Add the withDiskCache(true) option when building the GfpAdLoader object used for ad loading.

val adLoader = GfpAdLoader.Builder(context, adParam)
// . . .
.withDiskCache(true)
.build()

adLoader.loadAd()

Detailed Behavior

  • When loadAd() is executed, it loads the disk-cached ad and simultaneously automatically requests and disk-caches the next ad for the same ad unit ID
  • If there is no disk-cached ad, it loads the ad in the same way as a normal GfpAdLoader (same as automatically disk-caching the next ad)
  • The process of automatically loading the next ad is performed on a Worker Thread
info

On the first attempt after applying this option, there is no cached ad, so a normal ad request and load is performed. At this time, the next ad is automatically cached, so you can load the disk-cached ad from the second attempt.


2. Using GfpAdCacheManager

You can use GfpAdCacheManager to manually cache or load ads and receive callbacks for them.


GfpAdCacheManager.prefetch

Ad disk caching function, used when you need to additionally cache multiple ad responses besides the automatically cached next ad.

ParameterDescription
contextcontext
adUnitIdAd unit ID to cache
typeAd type to cache
callbackDisk caching callback triggered on success and failure
// Ad disk caching
GfpAdCacheManager.prefetch(context, "AOS_NATIVE_EXAMPLE", GfpAdCacheType.Native, object : GfpAdCacheManager.PrefetchCallback {
override fun onSuccess() {
// Ad caching success
}
override fun onFailure(error: GfpAdCacheError) {
// Ad caching failure
}
)
info

This function includes File I/O operations internally, so it is recommended to execute it on a Worker Thread.


GfpAdCacheManager.load

Disk-cached ad loading function that allows automatic caching of the next ad simultaneously with loading through parameters.

ParameterDescription
contextcontext
adUnitIdAd unit ID to load
typeAd type to load
callbackLoad callback for cached ads that triggers the ad response object (AdCallResponse) on success
autoPrefetchNextWhether to automatically cache 1 new ad for the ad unit ID
prefetchCallbackCallback for new ad caching when autoPrefetchNext = true
// Load disk-cached ad
GfpAdCacheManager.load(context, "AOS_NATIVE_EXAMPLE", GfpAdCacheType.Native, object : GfpAdCacheManager.LoadCallback {
override fun onSuccess(adCallResponse: AdCallResponse) {
// Cached ad load success
// Can be loaded directly through adLoader
adLoader.loadAd(adCallResponse)
}
override fun onFailure(error: GfpAdCacheError) {
// Cached ad load failure
// Attempt to load using the normal method through adLoader
adLoader.loadAd()
}
)
info

The ad caching task performed through autoPrefetchNext is executed on a Worker Thread. Therefore, prefetchCallback is also triggered on the Worker Thread, so UI operations in that callback function may not work properly


GfpAdCacheManager.clear

Delete ad response cache files corresponding to a specific ad unit ID

ParameterDescription
contextcontext
adUnitIdAd unit ID to delete
GfpAdCacheManager.clear(context, "AOS_NATIVE_EXAMPLE")

GfpAdCacheManager.clearAll

Delete all ad response cache files

ParameterDescription
contextcontext
GfpAdCacheManager.clearAll(context)

GfpAdCacheError

Caching-related error class

TypeDescription
NotFoundNo cached ad
InvalidAd that cannot be cached (not an S2S ad or no-fill ad response occurred)
FileIOFile I/O related error occurred during disk operation
LimitExceededMaximum number of ads that can be cached per adUnitId exceeded (5)

FAQ

  • Where are cache files stored?
    • Cached ad responses and resources are stored in the cache directory (cacheDir).
  • What happens when loading if there are multiple cached ads?
    • When loading cached ads, ads that were cached longer ago are used first.
  • What are the criteria for cacheable ads?
    • Caching is only possible for ad unit IDs that only have S2S ads integrated, and empty (no-fill) ad responses are not cached.
  • Is there a limit to the number of ads that can be cached?
    • Up to 5 ads can be cached on the device per ad unit ID, and caching attempts exceeding this limit will fail.
  • How long are cached files retained?
    • Loaded ads are immediately deleted, and ad response and resource cache files older than 7 days are not used and are deleted.
  • What happens when the service app version changes?
    • When the service app version changes, all files cached in the previous version are not used and are deleted.