Skip to content

Commit

Permalink
Disable cache every query on ets
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Rajabi committed Oct 28, 2018
1 parent d430134 commit b70f37d
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions lib/ecto_cassandra/adapter/base.ex
Expand Up @@ -5,7 +5,8 @@ defmodule EctoCassandra.Adapter.Base do
quote do
def prepare(type, query) do
cql = apply(EctoCassandra, type, [query])
{:cache, {:erlang.phash2(query), type, cql}}
# {:cache, {:erlang.phash2(query), type, cql}}
{:nocache, {query, type, cql}}
end

def execute(repo, _meta, {:cache, update, {hash, type, cql}}, params, _process, options) do
Expand All @@ -26,13 +27,9 @@ defmodule EctoCassandra.Adapter.Base do

def insert(repo, %{source: {prefix, source}, schema: schema}, fields, on_conflict, autogenerate, options) do
types = schema.__schema__(:types)
{field_names, values} = Enum.unzip(fields)
{_field_names, values} = Enum.unzip(fields)
{query_options, options} = Enum.split_with(options, fn {key, _} -> key in [:if, :using] end)
key = :erlang.phash2({prefix, source, field_names, autogenerate, types, query_options})
{:insert, cql} = Cassandra.Cache.put_new_lazy repo, key, fn ->
cql = EctoCassandra.insert(prefix, source, fields, autogenerate, types, query_options)
{:ok, {:insert, cql}}
end
cql = EctoCassandra.insert(prefix, source, fields, autogenerate, types, query_options)
options = Keyword.put(options, :values, values)
[repo, cql, options, on_conflict]
end
Expand All @@ -48,26 +45,18 @@ defmodule EctoCassandra.Adapter.Base do

def update(repo, %{source: {prefix, source}, schema: schema}, fields, filters, [], options) do
types = schema.__schema__(:types)
{field_names, values} = Enum.unzip(fields)
{_field_names, values} = Enum.unzip(fields)
{filters, filter_values} = Enum.unzip(filters)
{query_options, options} = Enum.split_with(options, fn {key, _} -> key in [:if, :using] end)
key = :erlang.phash2({prefix, source, field_names, filters, types, query_options})
{:update, cql} = Cassandra.Cache.put_new_lazy repo, key, fn ->
cql = EctoCassandra.update(prefix, source, fields, filters, types, query_options)
{:ok, {:update, cql}}
end
cql = EctoCassandra.update(prefix, source, fields, filters, types, query_options)
options = Keyword.put(options, :values, values ++ filter_values)
[repo, cql, options]
end

def delete(repo, %{source: {prefix, source}}, filters, options) do
{query_options, options} = Enum.split_with(options, fn {key, _} -> key in [:if, :using] end)
{filters, filter_values} = Enum.unzip(filters)
key = :erlang.phash2({prefix, source, filters, query_options})
{:delete, cql} = Cassandra.Cache.put_new_lazy repo, key, fn ->
cql = EctoCassandra.delete(prefix, source, filters, query_options)
{:ok, {:delete, cql}}
end
cql = EctoCassandra.delete(prefix, source, filters, query_options)
options = Keyword.put(options, :values, filter_values)
[repo, cql, options]
end
Expand Down

0 comments on commit b70f37d

Please sign in to comment.