{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.Lightsail.Types.CacheBehavior
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Lightsail.Types.CacheBehavior where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Lightsail.Types.BehaviorEnum
import qualified Amazonka.Prelude as Prelude

-- | Describes the default cache behavior of an Amazon Lightsail content
-- delivery network (CDN) distribution.
--
-- /See:/ 'newCacheBehavior' smart constructor.
data CacheBehavior = CacheBehavior'
  { -- | The cache behavior of the distribution.
    --
    -- The following cache behaviors can be specified:
    --
    -- -   __@cache@__ - This option is best for static sites. When specified,
    --     your distribution caches and serves your entire website as static
    --     content. This behavior is ideal for websites with static content
    --     that doesn\'t change depending on who views it, or for websites that
    --     don\'t use cookies, headers, or query strings to personalize
    --     content.
    --
    -- -   __@dont-cache@__ - This option is best for sites that serve a mix of
    --     static and dynamic content. When specified, your distribution caches
    --     and serve only the content that is specified in the distribution\'s
    --     @CacheBehaviorPerPath@ parameter. This behavior is ideal for
    --     websites or web applications that use cookies, headers, and query
    --     strings to personalize content for individual users.
    CacheBehavior -> Maybe BehaviorEnum
behavior :: Prelude.Maybe BehaviorEnum
  }
  deriving (CacheBehavior -> CacheBehavior -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CacheBehavior -> CacheBehavior -> Bool
$c/= :: CacheBehavior -> CacheBehavior -> Bool
== :: CacheBehavior -> CacheBehavior -> Bool
$c== :: CacheBehavior -> CacheBehavior -> Bool
Prelude.Eq, ReadPrec [CacheBehavior]
ReadPrec CacheBehavior
Int -> ReadS CacheBehavior
ReadS [CacheBehavior]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CacheBehavior]
$creadListPrec :: ReadPrec [CacheBehavior]
readPrec :: ReadPrec CacheBehavior
$creadPrec :: ReadPrec CacheBehavior
readList :: ReadS [CacheBehavior]
$creadList :: ReadS [CacheBehavior]
readsPrec :: Int -> ReadS CacheBehavior
$creadsPrec :: Int -> ReadS CacheBehavior
Prelude.Read, Int -> CacheBehavior -> ShowS
[CacheBehavior] -> ShowS
CacheBehavior -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CacheBehavior] -> ShowS
$cshowList :: [CacheBehavior] -> ShowS
show :: CacheBehavior -> String
$cshow :: CacheBehavior -> String
showsPrec :: Int -> CacheBehavior -> ShowS
$cshowsPrec :: Int -> CacheBehavior -> ShowS
Prelude.Show, forall x. Rep CacheBehavior x -> CacheBehavior
forall x. CacheBehavior -> Rep CacheBehavior x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CacheBehavior x -> CacheBehavior
$cfrom :: forall x. CacheBehavior -> Rep CacheBehavior x
Prelude.Generic)

-- |
-- Create a value of 'CacheBehavior' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'behavior', 'cacheBehavior_behavior' - The cache behavior of the distribution.
--
-- The following cache behaviors can be specified:
--
-- -   __@cache@__ - This option is best for static sites. When specified,
--     your distribution caches and serves your entire website as static
--     content. This behavior is ideal for websites with static content
--     that doesn\'t change depending on who views it, or for websites that
--     don\'t use cookies, headers, or query strings to personalize
--     content.
--
-- -   __@dont-cache@__ - This option is best for sites that serve a mix of
--     static and dynamic content. When specified, your distribution caches
--     and serve only the content that is specified in the distribution\'s
--     @CacheBehaviorPerPath@ parameter. This behavior is ideal for
--     websites or web applications that use cookies, headers, and query
--     strings to personalize content for individual users.
newCacheBehavior ::
  CacheBehavior
newCacheBehavior :: CacheBehavior
newCacheBehavior =
  CacheBehavior' {$sel:behavior:CacheBehavior' :: Maybe BehaviorEnum
behavior = forall a. Maybe a
Prelude.Nothing}

-- | The cache behavior of the distribution.
--
-- The following cache behaviors can be specified:
--
-- -   __@cache@__ - This option is best for static sites. When specified,
--     your distribution caches and serves your entire website as static
--     content. This behavior is ideal for websites with static content
--     that doesn\'t change depending on who views it, or for websites that
--     don\'t use cookies, headers, or query strings to personalize
--     content.
--
-- -   __@dont-cache@__ - This option is best for sites that serve a mix of
--     static and dynamic content. When specified, your distribution caches
--     and serve only the content that is specified in the distribution\'s
--     @CacheBehaviorPerPath@ parameter. This behavior is ideal for
--     websites or web applications that use cookies, headers, and query
--     strings to personalize content for individual users.
cacheBehavior_behavior :: Lens.Lens' CacheBehavior (Prelude.Maybe BehaviorEnum)
cacheBehavior_behavior :: Lens' CacheBehavior (Maybe BehaviorEnum)
cacheBehavior_behavior = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CacheBehavior' {Maybe BehaviorEnum
behavior :: Maybe BehaviorEnum
$sel:behavior:CacheBehavior' :: CacheBehavior -> Maybe BehaviorEnum
behavior} -> Maybe BehaviorEnum
behavior) (\s :: CacheBehavior
s@CacheBehavior' {} Maybe BehaviorEnum
a -> CacheBehavior
s {$sel:behavior:CacheBehavior' :: Maybe BehaviorEnum
behavior = Maybe BehaviorEnum
a} :: CacheBehavior)

instance Data.FromJSON CacheBehavior where
  parseJSON :: Value -> Parser CacheBehavior
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CacheBehavior"
      ( \Object
x ->
          Maybe BehaviorEnum -> CacheBehavior
CacheBehavior' forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"behavior")
      )

instance Prelude.Hashable CacheBehavior where
  hashWithSalt :: Int -> CacheBehavior -> Int
hashWithSalt Int
_salt CacheBehavior' {Maybe BehaviorEnum
behavior :: Maybe BehaviorEnum
$sel:behavior:CacheBehavior' :: CacheBehavior -> Maybe BehaviorEnum
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe BehaviorEnum
behavior

instance Prelude.NFData CacheBehavior where
  rnf :: CacheBehavior -> ()
rnf CacheBehavior' {Maybe BehaviorEnum
behavior :: Maybe BehaviorEnum
$sel:behavior:CacheBehavior' :: CacheBehavior -> Maybe BehaviorEnum
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe BehaviorEnum
behavior

instance Data.ToJSON CacheBehavior where
  toJSON :: CacheBehavior -> Value
toJSON CacheBehavior' {Maybe BehaviorEnum
behavior :: Maybe BehaviorEnum
$sel:behavior:CacheBehavior' :: CacheBehavior -> Maybe BehaviorEnum
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Key
"behavior" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe BehaviorEnum
behavior]
      )