Repository: whitfin/cachex (elixir)

Issue:
The :transactional option should be renamed to :transactions
Super low hanging fruit that I've left around for (literally) years. The name `:transactional` doesn't really fit with the rest of the options, so `:transactions` is much better. It's a breaking change so I was waiting for the next major to have some substance before filing this.

Pull request description:
Rename transactional to transactions in options structs
This fixes #335.

This renames the `:transactional` flag to be more consistent with other options, now named `:transactions`.

Patch:
diff --git a/docs/getting-started.md b/docs/getting-started.md
index 6fd827e..23fbb75 100644
--- a/docs/getting-started.md
+++ b/docs/getting-started.md
@@ -21,7 +21,7 @@ The second and third arguments are both optional and represent cache and server
 |       hooks      |     list of `hook()`     |        A list of execution hooks to listen on cache actions.       |
 |       limit      |    a `limit()` record    |    An integer or Limit struct to define the bounds of this cache.  |
 |       stats      |          boolean         |         Whether to track statistics for this cache or not.         |
-|   transactional  |          boolean         |           Whether to turn on transactions at cache start.          |
+|   transactions   |          boolean         |           Whether to turn on transactions at cache start.          |
 |      warmers     |    list of `warmer()`    |           A list of cache warmers to enable on the cache.          |
 
 ## Main Interface
diff --git a/lib/cachex.ex b/lib/cachex.ex
index c5df593..cfa7700 100644
--- a/lib/cachex.ex
+++ b/lib/cachex.ex
@@ -89,8 +89,6 @@ defmodule Cachex do
     put_many: [2, 3],
     refresh: [2, 3],
     reset: [1, 2],
-    set: [3, 4],
-    set_many: [2, 3],
     size: [1, 2],
     stats: [1, 2],
     stream: [1, 2, 3],
@@ -291,7 +289,7 @@ defmodule Cachex do
           iex> Cachex.start_link(:my_cache, [ stats: true ])
           { :ok, _pid }
 
-    * `:transactional`
+    * `:transactions`
 
       This option will specify whether this cache should have transactions and row
       locking enabled from cache startup. Please note that even if this is false,
@@ -1147,24 +1145,6 @@ defmodule Cachex do
   def reset(cache, options \\ []) when is_list(options),
     do: Router.call(cache, {:reset, [options]})
 
-  @doc """
-  Deprecated implementation delegate of `put/4`.
-  """
-  if Version.match?(System.version(), ">= 1.6.0"),
-    do: @deprecated("Please migrate to using put/4 instead.")
-
-  def set(cache, key, value, options \\ []),
-    do: put(cache, key, value, options)
-
-  @doc """
-  Deprecated implementation delegate of `put_many/3`.
-  """
-  if Version.match?(System.version(), ">= 1.6.0"),
-    do: @deprecated("Please migrate to using put_many/3 instead.")
-
-  def set_many(cache, pairs, options \\ []),
-    do: put_many(cache, pairs, options)
-
   @doc """
   Retrieves the total size of a cache.
 
@@ -1318,14 +1298,14 @@ defmodule Cachex do
       when is_function(operation, 1) and is_list(keys) and is_list(options) do
     Overseer.enforce cache do
       trans_cache =
-        case cache(cache, :transactional) do
+        case cache(cache, :transactions) do
           true ->
             cache
 
           false ->
             cache
             |> cache(:name)
-            |> Overseer.update(&cache(&1, transactional: true))
+            |> Overseer.update(&cache(&1, transactions: true))
         end
 
       Router.call(trans_cache, {:transaction, [keys, operation, options]})
diff --git a/lib/cachex/options.ex b/lib/cachex/options.ex
index 3e3743f..c145a43 100644
--- a/lib/cachex/options.ex
+++ b/lib/cachex/options.ex
@@ -25,7 +25,7 @@ defmodule Cachex.Options do
     :fallback,
     :compressed,
     :expiration,
-    :transactional,
+    :transactions,
     :warmers
   ]
 
@@ -325,12 +325,12 @@ defmodule Cachex.Options do
 
   # Configures a cache based on transaction flags.
   #
-  # This will simply configure the `:transactional` field in the cache
+  # This will simply configure the `:transactions` field in the cache
   # record and return the modified record with the flag attached.
-  defp parse_type(:transactional, cache, options),
+  defp parse_type(:transactions, cache, options),
     do:
       cache(cache,
-        transactional: get(options, :transactional, &is_boolean/1, false)
+        transactions: get(options, :transactions, &is_boolean/1, false)
       )
 
   # Configures any warmers assigned to the cache.
diff --git a/lib/cachex/services/locksmith.ex b/lib/cachex/services/locksmith.ex
index 0f50822..cf53d5c 100644
--- a/lib/cachex/services/locksmith.ex
+++ b/lib/cachex/services/locksmith.ex
@@ -156,7 +156,7 @@ defmodule Cachex.Services.Locksmith do
   our ETS writes are atomic and so do not require a lock.
   """
   @spec write(Cachex.Spec.cache(), any, (-> any)) :: any
-  def write(cache(transactional: false), _keys, fun),
+  def write(cache(transactions: false), _keys, fun),
     do: fun.()
 
   def write(cache() = cache, keys, fun) do
diff --git a/lib/cachex/spec.ex b/lib/cachex/spec.ex
index 021f0b9..f46e9a9 100644
--- a/lib/cachex/spec.ex
+++ b/lib/cachex/spec.ex
@@ -35,7 +35,7 @@ defmodule Cachex.Spec do
             limit: limit,
             nodes: [atom],
             ordered: boolean,
-            transactional: boolean,
+            transactions: boolean,
             warmers: [warmer]
           )
 
@@ -126,7 +126,7 @@ defmodule Cachex.Spec do
     limit: nil,
     nodes: [],
     ordered: false,
-    transactional: false,
+    transactions: false,
     warmers: []
 
   @doc """


Test patch:
diff --git a/test/cachex/actions/inspect_test.exs b/test/cachex/actions/inspect_test.exs
index 723d5d0..17478a4 100644
--- a/test/cachex/actions/inspect_test.exs
+++ b/test/cachex/actions/inspect_test.exs
@@ -138,7 +138,7 @@ defmodule Cachex.Actions.InspectTest do
     # update the state to have a different setting
     state2 =
       Services.Overseer.update(cache, fn state ->
-        cache(state, transactional: true)
+        cache(state, transactions: true)
       end)
 
     # retrieve the state via inspection
diff --git a/test/cachex/actions/set_many_test.exs b/test/cachex/actions/set_many_test.exs
deleted file mode 100644
index de62aa6..0000000
--- a/test/cachex/actions/set_many_test.exs
+++ /dev/null
@@ -1,73 +0,0 @@
-defmodule Cachex.Actions.SetManyTest do
-  use CachexCase
-
-  # This test just covers the case of forwarding calls
-  # to set_many() through to put_many() in order to
-  # validate the backwards compatibility calls.
-  test "forwarding calls to put_many(2/3)" do
-    # create a test cache
-    cache = Helper.create_cache()
-
-    # set values in the cache
-    result1 = Cachex.set_many(cache, [{1, 1}, {2, 2}])
-    result2 = Cachex.set_many(cache, [{3, 3}, {4, 4}], ttl: 5000)
-
-    # verify the results of the writes
-    assert(result1 == {:ok, true})
-    assert(result2 == {:ok, true})
-
-    # retrieve the written value
-    result2 = Cachex.get(cache, 1)
-    result3 = Cachex.get(cache, 2)
-    result4 = Cachex.get(cache, 3)
-    result5 = Cachex.get(cache, 4)
-
-    # check that it was written
-    assert(result2 == {:ok, 1})
-    assert(result3 == {:ok, 2})
-    assert(result4 == {:ok, 3})
-    assert(result5 == {:ok, 4})
-
-    # check the ttl on the last calls
-    result6 = Cachex.ttl!(cache, 3)
-    result7 = Cachex.ttl!(cache, 4)
-
-    # the second should have a TTL around 5s
-    assert_in_delta(result6, 5000, 10)
-    assert_in_delta(result7, 5000, 10)
-  end
-
-  # This test verifies that this action is correctly distributed across
-  # a cache cluster, instead of just the local node. We're not concerned
-  # about the actual behaviour here, only the routing of the action.
-  @tag distributed: true
-  test "adding new entries to a cache cluster" do
-    # create a new cache cluster for cleaning
-    {cache, _nodes} = Helper.create_cache_cluster(2)
-
-    # we know that 2 & 3 hash to the same slots
-    {:ok, true} = Cachex.set_many(cache, [{2, 2}, {3, 3}])
-
-    # try to retrieve both of the set keys
-    get1 = Cachex.get(cache, 2)
-    get2 = Cachex.get(cache, 3)
-
-    # both should come back
-    assert(get1 == {:ok, 2})
-    assert(get2 == {:ok, 3})
-  end
-
-  # This test verifies that all keys in a set_many/3 must hash to the
-  # same slot in a cluster, otherwise a cross_slot error will occur.
-  @tag distributed: true
-  test "multiple slots will return a :cross_slot error" do
-    # create a new cache cluster for cleaning
-    {cache, _nodes} = Helper.create_cache_cluster(2)
-
-    # we know that 1 & 3 don't hash to the same slots
-    set_many = Cachex.set_many(cache, [{1, 1}, {3, 3}])
-
-    # so there should be an error
-    assert(set_many == {:error, :cross_slot})
-  end
-end
diff --git a/test/cachex/actions/set_test.exs b/test/cachex/actions/set_test.exs
deleted file mode 100644
index c32284f..0000000
--- a/test/cachex/actions/set_test.exs
+++ /dev/null
@@ -1,54 +0,0 @@
-defmodule Cachex.Actions.SetTest do
-  use CachexCase
-
-  # This test just covers the case of forwarding calls
-  # to set() through to put() in order to validate the
-  # backwards compatibility of the deprecated calls.
-  test "forwarding calls to put(3/4)" do
-    # create a test cache
-    cache = Helper.create_cache()
-
-    # set values in the cache
-    result1 = Cachex.set(cache, 1, 1)
-    result2 = Cachex.set(cache, 2, 2, ttl: 5000)
-
-    # verify the results of the writes
-    assert(result1 == {:ok, true})
-    assert(result2 == {:ok, true})
-
-    # retrieve the written value
-    result2 = Cachex.get(cache, 1)
-    result3 = Cachex.get(cache, 2)
-
-    # check that it was written
-    assert(result2 == {:ok, 1})
-    assert(result3 == {:ok, 2})
-
-    # check the ttl on the second call
-    result4 = Cachex.ttl!(cache, 2)
-
-    # the second should have a TTL around 5s
-    assert_in_delta(result4, 5000, 10)
-  end
-
-  # This test verifies that this action is correctly distributed across
-  # a cache cluster, instead of just the local node. We're not concerned
-  # about the actual behaviour here, only the routing of the action.
-  @tag distributed: true
-  test "forwarding calls to put(3/4) in a cache cluster" do
-    # create a new cache cluster for cleaning
-    {cache, _nodes} = Helper.create_cache_cluster(2)
-
-    # we know that 1 & 2 hash to different nodes
-    {:ok, true} = Cachex.set(cache, 1, 1)
-    {:ok, true} = Cachex.set(cache, 2, 2)
-
-    # check the results of the calls across nodes
-    size1 = Cachex.size(cache, local: true)
-    size2 = Cachex.size(cache, local: false)
-
-    # one local, two total
-    assert(size1 == {:ok, 1})
-    assert(size2 == {:ok, 2})
-  end
-end
diff --git a/test/cachex/actions/transaction_test.exs b/test/cachex/actions/transaction_test.exs
index 4dbe196..8736104 100644
--- a/test/cachex/actions/transaction_test.exs
+++ b/test/cachex/actions/transaction_test.exs
@@ -10,7 +10,7 @@ defmodule Cachex.Actions.TransactionTest do
   # the value for the first time.
   test "executing a transaction is atomic" do
     # create a test cache
-    cache = Helper.create_cache(transactional: true)
+    cache = Helper.create_cache(transactions: true)
 
     # spawn a transaction to increment a key
     spawn(fn ->
@@ -67,7 +67,7 @@ defmodule Cachex.Actions.TransactionTest do
     state1 = Services.Overseer.retrieve(cache)
 
     # verify transactions are disabled
-    assert(cache(state1, :transactional) == false)
+    assert(cache(state1, :transactions) == false)
 
     # execute a transactions
     Cachex.transaction(cache, [], & &1)
@@ -76,7 +76,7 @@ defmodule Cachex.Actions.TransactionTest do
     state2 = Services.Overseer.retrieve(cache)
 
     # verify transactions are now enabled
-    assert(cache(state2, :transactional) == true)
+    assert(cache(state2, :transactions) == true)
   end
 
   # This test verifies that this action is correctly distributed across
diff --git a/test/cachex/options_test.exs b/test/cachex/options_test.exs
index 4e00dab..5c36f6a 100644
--- a/test/cachex/options_test.exs
+++ b/test/cachex/options_test.exs
@@ -370,18 +370,18 @@ defmodule Cachex.OptionsTest do
   # a cache has them enabled or disabled. This is simply checking whether the flag
   # is set to true or false, and the default. We also verify that the transaction
   # locksmith has its name set inside the returned state.
-  test "parsing :transactional flags" do
+  test "parsing :transactions flags" do
     # grab a cache name
     name = Helper.create_name()
 
     # parse our values as options
-    {:ok, cache(transactional: trans1)} =
-      Cachex.Options.parse(name, transactional: true)
+    {:ok, cache(transactions: trans1)} =
+      Cachex.Options.parse(name, transactions: true)
 
-    {:ok, cache(transactional: trans2)} =
-      Cachex.Options.parse(name, transactional: false)
+    {:ok, cache(transactions: trans2)} =
+      Cachex.Options.parse(name, transactions: false)
 
-    {:ok, cache(transactional: trans3)} = Cachex.Options.parse(name, [])
+    {:ok, cache(transactions: trans3)} = Cachex.Options.parse(name, [])
 
     # the first one should be truthy, and the latter two falsey
     assert trans1
diff --git a/test/cachex/services/locksmith_test.exs b/test/cachex/services/locksmith_test.exs
index 7d62e25..335d493 100644
--- a/test/cachex/services/locksmith_test.exs
+++ b/test/cachex/services/locksmith_test.exs
@@ -31,8 +31,8 @@ defmodule Cachex.Services.LocksmithTest do
   # ensure that writes are queued unnecessarily.
   test "executing a write outside of a transaction" do
     # start two caches, one transactional, one not
-    cache1 = Helper.create_cache(transactional: true)
-    cache2 = Helper.create_cache(transactional: false)
+    cache1 = Helper.create_cache(transactions: true)
+    cache2 = Helper.create_cache(transactions: false)
 
     # fetch the states for the caches
     state1 = Services.Overseer.retrieve(cache1)
@@ -59,8 +59,8 @@ defmodule Cachex.Services.LocksmithTest do
   # itself, as it's needed to test the write execution.
   test "executing a transactional block" do
     # start two caches, one transactional, one not
-    cache1 = Helper.create_cache(transactional: false)
-    cache2 = Helper.create_cache(transactional: true)
+    cache1 = Helper.create_cache(transactions: false)
+    cache2 = Helper.create_cache(transactions: true)
 
     # fetch the states for the caches
     state1 = Services.Overseer.retrieve(cache1)
@@ -174,7 +174,7 @@ defmodule Cachex.Services.LocksmithTest do
     assert(Enum.sort(locked5) == ["key1", "key2", "key3"])
   end
 
-  # The Locksmith provides a `transactional/1` function to set the current
+  # The Locksmith provides a `start_transaction/1` function to set the current
   # process as transactional. This test just makes sure that this sets the flag
   # correctly between true/false.
   test "setting a transactional context" do
diff --git a/test/cachex_test.exs b/test/cachex_test.exs
index 19bd024..79d5d0d 100644
--- a/test/cachex_test.exs
+++ b/test/cachex_test.exs
@@ -177,7 +177,7 @@ defmodule CachexTest do
     assert(is_even(length(definitions)))
 
     # verify the size to cause errors on addition/removal
-    assert(length(definitions) == 156)
+    assert(length(definitions) == 148)
 
     # validate all definitions
     for {name, arity} <- definitions do