Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
1weather
Commits
50d865b5
Commit
50d865b5
authored
Apr 13, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A9Cache: support for limiting the max number of items cached for a given slot id.
parent
075430dc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
4 deletions
+16
-4
1Weather/Ads/AmazonA9/A9Cache.swift
+8
-3
1Weather/Ads/Configuration/AdConfig.swift
+8
-1
No files found.
1Weather/Ads/AmazonA9/A9Cache.swift
View file @
50d865b5
...
@@ -157,14 +157,19 @@ class A9Cache {
...
@@ -157,14 +157,19 @@ class A9Cache {
log
.
error
(
"Couldn't start a9 preload for slotId
\(
slotId
)
adType
\(
adType
)
: failed to determine adSize!"
)
log
.
error
(
"Couldn't start a9 preload for slotId
\(
slotId
)
adType
\(
adType
)
: failed to determine adSize!"
)
fatalError
()
fatalError
()
}
}
let
maxCount
=
configManager
.
adConfig
.
a9MaxCachedPerPlacement
var
uncappedCount
=
count
if
let
cacheItem
=
cacheItems
[
slotId
]
{
if
let
cacheItem
=
cacheItems
[
slotId
]
{
cacheItem
.
countToCache
+=
count
uncappedCount
=
cacheItem
.
countToCache
+
count
cacheItem
.
countToCache
=
min
(
uncappedCount
,
maxCount
)
}
}
else
{
else
{
let
newCacheItem
=
A9CacheItem
(
slotId
:
slotId
,
adSize
:
adSize
,
count
:
count
,
cache
:
self
)
let
newCacheItem
=
A9CacheItem
(
slotId
:
slotId
,
adSize
:
adSize
,
count
:
min
(
uncappedCount
,
maxCount
)
,
cache
:
self
)
cacheItems
[
slotId
]
=
newCacheItem
cacheItems
[
slotId
]
=
newCacheItem
}
}
if
uncappedCount
>
maxCount
{
log
.
debug
(
"Limit cached count for slotId
\(
slotId
)
to
\(
maxCount
)
"
)
}
}
}
private
func
preloadAllIfNeeded
()
{
private
func
preloadAllIfNeeded
()
{
...
...
1Weather/Ads/Configuration/AdConfig.swift
View file @
50d865b5
...
@@ -9,8 +9,11 @@
...
@@ -9,8 +9,11 @@
import
UIKit
import
UIKit
struct
AdConfig
:
Codable
{
struct
AdConfig
:
Codable
{
private
static
let
defaultA9MaxCachedPerPlacement
:
UInt
=
2
var
adsEnabled
:
Bool
var
adsEnabled
:
Bool
var
a9RefreshRate
:
Int
var
a9RefreshRate
:
Int
var
a9MaxCachedPerPlacement
:
UInt
var
placements
:
[
AdPlacementName
:
AdPlacement
]?
var
placements
:
[
AdPlacementName
:
AdPlacement
]?
var
nativePlacements
:
[
AdPlacementName
:
NativeAdPlacement
]?
var
nativePlacements
:
[
AdPlacementName
:
NativeAdPlacement
]?
...
@@ -33,12 +36,14 @@ struct AdConfig: Codable {
...
@@ -33,12 +36,14 @@ struct AdConfig: Codable {
static
let
adsEnabled
=
CodingKeys
(
stringValue
:
"ads_enabled"
)
static
let
adsEnabled
=
CodingKeys
(
stringValue
:
"ads_enabled"
)
static
let
a9RefreshRate
=
CodingKeys
(
stringValue
:
"a9_refresh_rate"
)
static
let
a9RefreshRate
=
CodingKeys
(
stringValue
:
"a9_refresh_rate"
)
static
let
a9MaxCachedPerPlacement
=
CodingKeys
(
stringValue
:
"a9_max_cached_per_placement"
)
static
let
placements
=
CodingKeys
(
stringValue
:
"placements"
)
static
let
placements
=
CodingKeys
(
stringValue
:
"placements"
)
}
}
init
()
{
init
()
{
adsEnabled
=
true
adsEnabled
=
true
a9RefreshRate
=
0
a9RefreshRate
=
0
a9MaxCachedPerPlacement
=
AdConfig
.
defaultA9MaxCachedPerPlacement
}
}
init
(
from
decoder
:
Decoder
)
throws
{
init
(
from
decoder
:
Decoder
)
throws
{
...
@@ -46,7 +51,9 @@ struct AdConfig: Codable {
...
@@ -46,7 +51,9 @@ struct AdConfig: Codable {
adsEnabled
=
try
container
.
decode
(
Bool
.
self
,
forKey
:
.
adsEnabled
)
adsEnabled
=
try
container
.
decode
(
Bool
.
self
,
forKey
:
.
adsEnabled
)
a9RefreshRate
=
try
container
.
decode
(
Int
.
self
,
forKey
:
.
a9RefreshRate
)
a9RefreshRate
=
try
container
.
decode
(
Int
.
self
,
forKey
:
.
a9RefreshRate
)
a9MaxCachedPerPlacement
=
try
container
.
decodeIfPresent
(
UInt
.
self
,
forKey
:
.
a9MaxCachedPerPlacement
)
??
AdConfig
.
defaultA9MaxCachedPerPlacement
if
container
.
contains
(
.
placements
)
{
if
container
.
contains
(
.
placements
)
{
let
allPlacementsContainer
=
try
container
.
nestedContainer
(
keyedBy
:
CodingKeys
.
self
,
forKey
:
.
placements
)
let
allPlacementsContainer
=
try
container
.
nestedContainer
(
keyedBy
:
CodingKeys
.
self
,
forKey
:
.
placements
)
var
placements
=
[
AdPlacementName
:
AdPlacement
](
minimumCapacity
:
allPlacementsContainer
.
allKeys
.
count
)
var
placements
=
[
AdPlacementName
:
AdPlacement
](
minimumCapacity
:
allPlacementsContainer
.
allKeys
.
count
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment