Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable increasing load from switchboard #27236

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions common/app/conf/switches/PerformanceSwitches.scala
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,24 @@ trait PerformanceSwitches {
sellByDate = never,
exposeClientSide = true,
)

val ShorterSurrogateCacheForRecentArticles = Switch(
SwitchGroup.Performance,
"shorter-surrogate-cache-for-recent-articles",
"Shorten the surrogate cache time for recent articles for load testing",
owners = Seq(Owner.withEmail("[email protected]")),
safeState = Off,
sellByDate = LocalDate.of(2024, 7, 1),
exposeClientSide = false,
)

val ShorterSurrogateCacheForOlderArticles = Switch(
SwitchGroup.Performance,
"shorter-surrogate-cache-for-older-articles",
"Shorten the surrogate cache time for older articles for load testing",
owners = Seq(Owner.withEmail("[email protected]")),
safeState = Off,
sellByDate = LocalDate.of(2024, 7, 1),
exposeClientSide = false,
)
}
16 changes: 10 additions & 6 deletions common/app/model/Cached.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package model

import conf.switches.Switches.LongCacheSwitch
import conf.switches.Switches.ShorterSurrogateCacheForOlderArticles
import conf.switches.Switches.ShorterSurrogateCacheForRecentArticles
import org.joda.time.DateTime
import play.api.http.Writeable
import play.api.mvc._
Expand All @@ -17,17 +19,17 @@ object CacheTime {

object Default extends CacheTime(60)
object LiveBlogActive extends CacheTime(5, Some(60))
object RecentlyUpdated extends CacheTime(60)
def RecentlyUpdated = CacheTime(60, if (ShorterSurrogateCacheForRecentArticles.isSwitchedOn) Some(30) else None)
// There is lambda which invalidates the cache on press events, so the facia cache time can be high.
object Facia extends CacheTime(60, Some(900))
object ArchiveRedirect extends CacheTime(60, Some(300))
object ShareCount extends CacheTime(60, Some(600))
object NotFound extends CacheTime(10) // This will be overwritten by fastly
object DiscussionDefault extends CacheTime(60)
object DiscussionClosed extends CacheTime(60, Some(longCacheTime))

def LastDayUpdated: CacheTime = CacheTime(60, Some(longCacheTime))
def NotRecentlyUpdated: CacheTime = CacheTime(60, Some(longCacheTime))
private def oldArticleCacheTime = if (ShorterSurrogateCacheForOlderArticles.isSwitchedOn) 60 else longCacheTime
def LastDayUpdated = CacheTime(60, Some(oldArticleCacheTime))
def NotRecentlyUpdated = CacheTime(60, Some(oldArticleCacheTime))
}

object Cached extends implicits.Dates {
Expand Down Expand Up @@ -111,8 +113,10 @@ object Cached extends implicits.Dates {
private def cacheHeaders(cacheTime: CacheTime, result: Result, maybeEtag: Option[String]): Result = {
val now = DateTime.now

val surrogateMaxAge =
cacheTime.surrogateSeconds.filter(_ => LongCacheSwitch.isSwitchedOn).getOrElse(cacheTime.cacheSeconds)
val surrogateMaxAge = cacheTime.surrogateSeconds match {
case Some(age) if LongCacheSwitch.isSwitchedOn => age
case _ => cacheTime.cacheSeconds
}
Comment on lines +116 to +119
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored for readability


val etagHeaderString: String = maybeEtag.getOrElse(
s""""guRandomEtag${scala.util.Random.nextInt()}${scala.util.Random
Expand Down
Loading