{-# 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.AppSync.Types.CachingConfig
-- 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.AppSync.Types.CachingConfig where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude

-- | The caching configuration for a resolver that has caching activated.
--
-- /See:/ 'newCachingConfig' smart constructor.
data CachingConfig = CachingConfig'
  { -- | The caching keys for a resolver that has caching activated.
    --
    -- Valid values are entries from the @$context.arguments@,
    -- @$context.source@, and @$context.identity@ maps.
    CachingConfig -> Maybe [Text]
cachingKeys :: Prelude.Maybe [Prelude.Text],
    -- | The TTL in seconds for a resolver that has caching activated.
    --
    -- Valid values are 1–3,600 seconds.
    CachingConfig -> Integer
ttl :: Prelude.Integer
  }
  deriving (CachingConfig -> CachingConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CachingConfig -> CachingConfig -> Bool
$c/= :: CachingConfig -> CachingConfig -> Bool
== :: CachingConfig -> CachingConfig -> Bool
$c== :: CachingConfig -> CachingConfig -> Bool
Prelude.Eq, ReadPrec [CachingConfig]
ReadPrec CachingConfig
Int -> ReadS CachingConfig
ReadS [CachingConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CachingConfig]
$creadListPrec :: ReadPrec [CachingConfig]
readPrec :: ReadPrec CachingConfig
$creadPrec :: ReadPrec CachingConfig
readList :: ReadS [CachingConfig]
$creadList :: ReadS [CachingConfig]
readsPrec :: Int -> ReadS CachingConfig
$creadsPrec :: Int -> ReadS CachingConfig
Prelude.Read, Int -> CachingConfig -> ShowS
[CachingConfig] -> ShowS
CachingConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CachingConfig] -> ShowS
$cshowList :: [CachingConfig] -> ShowS
show :: CachingConfig -> String
$cshow :: CachingConfig -> String
showsPrec :: Int -> CachingConfig -> ShowS
$cshowsPrec :: Int -> CachingConfig -> ShowS
Prelude.Show, forall x. Rep CachingConfig x -> CachingConfig
forall x. CachingConfig -> Rep CachingConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CachingConfig x -> CachingConfig
$cfrom :: forall x. CachingConfig -> Rep CachingConfig x
Prelude.Generic)

-- |
-- Create a value of 'CachingConfig' 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:
--
-- 'cachingKeys', 'cachingConfig_cachingKeys' - The caching keys for a resolver that has caching activated.
--
-- Valid values are entries from the @$context.arguments@,
-- @$context.source@, and @$context.identity@ maps.
--
-- 'ttl', 'cachingConfig_ttl' - The TTL in seconds for a resolver that has caching activated.
--
-- Valid values are 1–3,600 seconds.
newCachingConfig ::
  -- | 'ttl'
  Prelude.Integer ->
  CachingConfig
newCachingConfig :: Integer -> CachingConfig
newCachingConfig Integer
pTtl_ =
  CachingConfig'
    { $sel:cachingKeys:CachingConfig' :: Maybe [Text]
cachingKeys = forall a. Maybe a
Prelude.Nothing,
      $sel:ttl:CachingConfig' :: Integer
ttl = Integer
pTtl_
    }

-- | The caching keys for a resolver that has caching activated.
--
-- Valid values are entries from the @$context.arguments@,
-- @$context.source@, and @$context.identity@ maps.
cachingConfig_cachingKeys :: Lens.Lens' CachingConfig (Prelude.Maybe [Prelude.Text])
cachingConfig_cachingKeys :: Lens' CachingConfig (Maybe [Text])
cachingConfig_cachingKeys = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CachingConfig' {Maybe [Text]
cachingKeys :: Maybe [Text]
$sel:cachingKeys:CachingConfig' :: CachingConfig -> Maybe [Text]
cachingKeys} -> Maybe [Text]
cachingKeys) (\s :: CachingConfig
s@CachingConfig' {} Maybe [Text]
a -> CachingConfig
s {$sel:cachingKeys:CachingConfig' :: Maybe [Text]
cachingKeys = Maybe [Text]
a} :: CachingConfig) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The TTL in seconds for a resolver that has caching activated.
--
-- Valid values are 1–3,600 seconds.
cachingConfig_ttl :: Lens.Lens' CachingConfig Prelude.Integer
cachingConfig_ttl :: Lens' CachingConfig Integer
cachingConfig_ttl = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CachingConfig' {Integer
ttl :: Integer
$sel:ttl:CachingConfig' :: CachingConfig -> Integer
ttl} -> Integer
ttl) (\s :: CachingConfig
s@CachingConfig' {} Integer
a -> CachingConfig
s {$sel:ttl:CachingConfig' :: Integer
ttl = Integer
a} :: CachingConfig)

instance Data.FromJSON CachingConfig where
  parseJSON :: Value -> Parser CachingConfig
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CachingConfig"
      ( \Object
x ->
          Maybe [Text] -> Integer -> CachingConfig
CachingConfig'
            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
"cachingKeys" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"ttl")
      )

instance Prelude.Hashable CachingConfig where
  hashWithSalt :: Int -> CachingConfig -> Int
hashWithSalt Int
_salt CachingConfig' {Integer
Maybe [Text]
ttl :: Integer
cachingKeys :: Maybe [Text]
$sel:ttl:CachingConfig' :: CachingConfig -> Integer
$sel:cachingKeys:CachingConfig' :: CachingConfig -> Maybe [Text]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
cachingKeys
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Integer
ttl

instance Prelude.NFData CachingConfig where
  rnf :: CachingConfig -> ()
rnf CachingConfig' {Integer
Maybe [Text]
ttl :: Integer
cachingKeys :: Maybe [Text]
$sel:ttl:CachingConfig' :: CachingConfig -> Integer
$sel:cachingKeys:CachingConfig' :: CachingConfig -> Maybe [Text]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
cachingKeys
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Integer
ttl

instance Data.ToJSON CachingConfig where
  toJSON :: CachingConfig -> Value
toJSON CachingConfig' {Integer
Maybe [Text]
ttl :: Integer
cachingKeys :: Maybe [Text]
$sel:ttl:CachingConfig' :: CachingConfig -> Integer
$sel:cachingKeys:CachingConfig' :: CachingConfig -> Maybe [Text]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"cachingKeys" 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 [Text]
cachingKeys,
            forall a. a -> Maybe a
Prelude.Just (Key
"ttl" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Integer
ttl)
          ]
      )