Permalink
Browse files

Stripped out Mnesia, implemented local transactions

  • Loading branch information...
whitfin committed Sep 9, 2016
1 parent ac3b071 commit bd41d54ffbe069657274999ac2678a843d3d4c52
Showing with 1,127 additions and 1,646 deletions.
  1. +2 −0 .gitignore
  2. +143 −48 bench/cachex_bench.exs
  3. +60 −73 lib/cachex.ex
  4. +108 −0 lib/cachex/actions.ex
  5. +24 −0 lib/cachex/actions/clear.ex
  6. +15 −0 lib/cachex/actions/count.ex
  7. +15 −0 lib/cachex/actions/del.ex
  8. +9 −0 lib/cachex/actions/execute.ex
  9. +21 −0 lib/cachex/actions/exists.ex
  10. +24 −0 lib/cachex/actions/expire.ex
  11. +35 −0 lib/cachex/actions/get.ex
  12. +33 −0 lib/cachex/actions/get_and_update.ex
  13. +36 −0 lib/cachex/actions/incr.ex
  14. +15 −0 lib/cachex/actions/keys.ex
  15. +13 −0 lib/cachex/actions/purge.ex
  16. +16 −0 lib/cachex/actions/refresh.ex
  17. +43 −0 lib/cachex/actions/reset.ex
  18. +19 −0 lib/cachex/actions/set.ex
  19. +12 −0 lib/cachex/actions/size.ex
  20. +20 −0 lib/cachex/actions/stats.ex
  21. +32 −0 lib/cachex/actions/stream.ex
  22. +29 −0 lib/cachex/actions/take.ex
  23. +22 −0 lib/cachex/actions/transaction.ex
  24. +25 −0 lib/cachex/actions/ttl.ex
  25. +15 −0 lib/cachex/actions/update.ex
  26. +2 −1 lib/cachex/application.ex
  27. +1 −1 lib/cachex/inspector.ex
  28. +2 −2 lib/cachex/janitor.ex
  29. +38 −0 lib/cachex/lock_manager.ex
  30. +32 −0 lib/cachex/lock_manager/server.ex
  31. +44 −0 lib/cachex/lock_manager/table.ex
  32. +16 −5 lib/cachex/options.ex
  33. +2 −2 lib/cachex/policy/lrw.ex
  34. +0 −1 lib/cachex/record.ex
  35. +15 −26 lib/cachex/state.ex
  36. +32 −70 lib/cachex/util.ex
  37. +0 −460 lib/cachex/worker.ex
  38. +0 −243 lib/cachex/worker/actions.ex
  39. +4 −3 mix.exs
  40. +4 −2 mix.lock
  41. +0 −15 test/cachex/abort_test.exs
  42. +1 −1 test/cachex/{ → actions}/clear_test.exs
  43. +1 −1 test/cachex/{ → actions}/count_test.exs
  44. +2 −2 test/cachex/{ → actions}/decr_test.exs
  45. +1 −1 test/cachex/{ → actions}/del_test.exs
  46. +1 −1 test/cachex/{ → actions}/empty_test.exs
  47. +1 −13 test/cachex/{ → actions}/execute_test.exs
  48. +1 −1 test/cachex/{ → actions}/exists_test.exs
  49. +1 −1 test/cachex/{ → actions}/expire_at_test.exs
  50. +1 −1 test/cachex/{ → actions}/expire_test.exs
  51. +1 −13 test/cachex/{ → actions}/get_and_update_test.exs
  52. +1 −1 test/cachex/{ → actions}/get_test.exs
  53. +2 −2 test/cachex/{ → actions}/incr_test.exs
  54. +1 −1 test/cachex/{ → actions}/keys_test.exs
  55. +1 −1 test/cachex/{ → actions}/persist_test.exs
  56. +1 −1 test/cachex/{ → actions}/purge_test.exs
  57. +1 −1 test/cachex/{ → actions}/refresh_test.exs
  58. +3 −3 test/cachex/{ → actions}/reset_test.exs
  59. +1 −1 test/cachex/{ → actions}/set_test.exs
  60. +1 −1 test/cachex/{ → actions}/size_test.exs
  61. +1 −1 test/cachex/{ → actions}/stats_test.exs
  62. +1 −1 test/cachex/{ → actions}/stream_test.exs
  63. +1 −1 test/cachex/{ → actions}/take_test.exs
  64. +20 −88 test/cachex/{ → actions}/transaction_test.exs
  65. +1 −1 test/cachex/{ → actions}/ttl_test.exs
  66. +1 −1 test/cachex/{ → actions}/update_test.exs
  67. +0 −95 test/cachex/get_and_update_raw_test.exs
  68. +60 −0 test/cachex/lock_manager_test.exs
  69. +1 −1 test/cachex/policy/lrw_test.exs
  70. +2 −3 test/cachex/state_test.exs
  71. +0 −333 test/cachex/stats/registry/remote_test.exs
  72. +1 −1 test/cachex/stats/{registry/local_test.exs → registry_test.exs}
  73. +16 −63 test/cachex/util_test.exs
  74. +18 −57 test/cachex_test.exs
  75. +3 −1 test/test_helper.exs
@@ -1,5 +1,7 @@
/_build
/_native
/bench
!/bench/cachex_bench.exs
/cover
/deps
/diff
@@ -1,49 +1,144 @@
one_hour = :timer.hours(1)
tomorrow = Cachex.Util.now() + (1000 * 60 * 60 * 24)
{ parsed, _argv, _errors } = OptionParser.parse(System.argv(), [
aliases: [ s: :state ],
strict: [ state: :boolean ]
])
Application.ensure_all_started(:cachex)
Cachex.start(:bench_cache)
Cachex.set(:bench_cache, "decr_test", 0)
Cachex.set(:bench_cache, "expire_at_test", "expire_at_value")
Cachex.set(:bench_cache, "expire_test", "expire_value")
Cachex.set(:bench_cache, "get_test", "get_value")
Cachex.set(:bench_cache, "gad_test", "gad_value")
Cachex.set(:bench_cache, "incr_test", 0)
Cachex.set(:bench_cache, "persist_test", 0)
Cachex.set(:bench_cache, "refresh_test", "refresh_value", ttl: one_hour)
Cachex.set(:bench_cache, "ttl_test", "ttl_value", ttl: one_hour)
Cachex.set(:bench_cache, "update_test", "update_value")
cache = if parsed[:with_state] do
Cachex.inspect!(:bench_cache, :state)
else
:bench_cache
end
defmodule CachexBench do
use Benchfella
@one_hour :timer.hours(1)
@tomorrow Cachex.Util.now() + (1000 * 60 * 60 * 24)
setup_all do
Application.ensure_all_started(:cachex)
Cachex.start(:bench_cache)
Cachex.set(:bench_cache, "decr_test", 0)
Cachex.set(:bench_cache, "expire_at_test", "expire_at_value")
Cachex.set(:bench_cache, "expire_test", "expire_value")
Cachex.set(:bench_cache, "get_test", "get_value")
Cachex.set(:bench_cache, "gad_test", "gad_value")
Cachex.set(:bench_cache, "incr_test", 0)
Cachex.set(:bench_cache, "persist_test", 0)
Cachex.set(:bench_cache, "refresh_test", "refresh_value", ttl: @one_hour)
Cachex.set(:bench_cache, "ttl_test", "ttl_value", ttl: @one_hour)
Cachex.set(:bench_cache, "update_test", "update_value")
{ parsed, _argv, _errors } = OptionParser.parse(System.argv(), [
aliases: [ s: :state, t: :transactions ],
strict: [ state: :boolean, transactions: :boolean ]
])
use_state = Keyword.get(parsed, :state, false)
use_trans = Keyword.get(parsed, :transactions, false)
if use_trans do
Cachex.State.update(:bench_cache, fn(state) ->
%Cachex.State{ state | transactions: true }
end)
end
cache = if use_state do
Cachex.inspect!(:bench_cache, :state)
else
:bench_cache
end
headr = """
Benching with state: #{use_state}
Benching with transactions: #{use_trans}
"""
IO.puts(headr)
{ :ok, cache }
end
bench "count" do
Cachex.count(bench_context)
:ok
end
bench "decr" do
Cachex.decr(bench_context, "decr_test")
:ok
end
bench "del" do
Cachex.del(bench_context, "del_test")
:ok
end
Benchee.run(%{ time: 5, warmup: 5, parallel: 1, print: %{ fast_warning: false, comparison: false } }, [
{ "count", fn -> Cachex.count(cache) end },
{ "decr", fn -> Cachex.decr(cache, "decr_test") end },
{ "del", fn -> Cachex.del(cache, "del_test") end },
{ "empty?", fn -> Cachex.empty?(cache) end },
{ "exists?", fn -> Cachex.exists?(cache, "exists_test") end },
{ "expire", fn -> Cachex.expire(cache, "expire_test", one_hour) end },
{ "expire_at", fn -> Cachex.expire_at(cache, "expire_at_test", tomorrow) end },
{ "get", fn -> Cachex.get(cache, "get_test") end },
{ "gad", fn -> Cachex.get_and_update(cache, "gad_test", &(&1)) end },
{ "incr", fn -> Cachex.incr(cache, "incr_test") end },
{ "keys", fn -> Cachex.keys(cache) end },
{ "persist", fn -> Cachex.persist(cache, "persist_test") end },
{ "refresh", fn -> Cachex.refresh(cache, "refresh_test") end },
{ "set", fn -> Cachex.set(cache, "set_test", "set_value") end },
{ "size", fn -> Cachex.size(cache) end },
{ "take", fn -> Cachex.take(cache, "take_test") end },
{ "ttl", fn -> Cachex.ttl(cache, "ttl_test") end },
{ "update", fn -> Cachex.update(cache, "update_test", "update_value") end }
])
bench "empty?" do
Cachex.empty?(bench_context)
:ok
end
bench "exists?" do
Cachex.exists?(bench_context, "exists_test")
:ok
end
bench "expire" do
Cachex.expire(bench_context, "expire_test", @one_hour)
:ok
end
bench "expire_at" do
Cachex.expire_at(bench_context, "expire_at_test", @tomorrow)
:ok
end
bench "get" do
Cachex.get(bench_context, "get_test")
:ok
end
bench "get_and_update" do
Cachex.get_and_update(bench_context, "gad_test", &(&1))
:ok
end
bench "incr" do
Cachex.incr(bench_context, "incr_test")
:ok
end
bench "keys" do
Cachex.keys(bench_context)
:ok
end
bench "persist" do
Cachex.persist(bench_context, "persist_test")
:ok
end
bench "refresh" do
Cachex.refresh(bench_context, "refresh_test")
:ok
end
bench "set" do
Cachex.set(bench_context, "set_test", "set_value")
:ok
end
bench "size" do
Cachex.size(bench_context)
:ok
end
bench "take" do
Cachex.take(bench_context, "take_test")
:ok
end
bench "ttl" do
Cachex.ttl(bench_context, "ttl_test")
:ok
end
bench "update" do
Cachex.update(bench_context, "update_test", "update_value")
:ok
end
end
Oops, something went wrong.

0 comments on commit bd41d54

Please sign in to comment.