{-# 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-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Lightsail.Types.CacheBehavior where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(CacheBehavior -> CacheBehavior -> Bool)
-> (CacheBehavior -> CacheBehavior -> Bool) -> Eq CacheBehavior
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]
(Int -> ReadS CacheBehavior)
-> ReadS [CacheBehavior]
-> ReadPrec CacheBehavior
-> ReadPrec [CacheBehavior]
-> Read 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
(Int -> CacheBehavior -> ShowS)
-> (CacheBehavior -> String)
-> ([CacheBehavior] -> ShowS)
-> Show CacheBehavior
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. CacheBehavior -> Rep CacheBehavior x)
-> (forall x. Rep CacheBehavior x -> CacheBehavior)
-> Generic CacheBehavior
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' :: Maybe BehaviorEnum -> CacheBehavior
CacheBehavior' {$sel:behavior:CacheBehavior' :: Maybe BehaviorEnum
behavior = Maybe BehaviorEnum
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 :: (Maybe BehaviorEnum -> f (Maybe BehaviorEnum))
-> CacheBehavior -> f CacheBehavior
cacheBehavior_behavior = (CacheBehavior -> Maybe BehaviorEnum)
-> (CacheBehavior -> Maybe BehaviorEnum -> CacheBehavior)
-> Lens
     CacheBehavior
     CacheBehavior
     (Maybe BehaviorEnum)
     (Maybe BehaviorEnum)
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 Core.FromJSON CacheBehavior where
  parseJSON :: Value -> Parser CacheBehavior
parseJSON =
    String
-> (Object -> Parser CacheBehavior)
-> Value
-> Parser CacheBehavior
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CacheBehavior"
      ( \Object
x ->
          Maybe BehaviorEnum -> CacheBehavior
CacheBehavior' (Maybe BehaviorEnum -> CacheBehavior)
-> Parser (Maybe BehaviorEnum) -> Parser CacheBehavior
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe BehaviorEnum)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"behavior")
      )

instance Prelude.Hashable CacheBehavior

instance Prelude.NFData CacheBehavior

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