object: split object_cache from user_cache

This commit is contained in:
William Pitcock 2018-11-01 08:30:10 +00:00
parent 2c092ed355
commit 2b3a40d038
3 changed files with 26 additions and 10 deletions

View file

@ -16,14 +16,30 @@ defmodule Pleroma.Application do
supervisor(Pleroma.Web.Endpoint, []), supervisor(Pleroma.Web.Endpoint, []),
# Start your own worker by calling: Pleroma.Worker.start_link(arg1, arg2, arg3) # Start your own worker by calling: Pleroma.Worker.start_link(arg1, arg2, arg3)
# worker(Pleroma.Worker, [arg1, arg2, arg3]), # worker(Pleroma.Worker, [arg1, arg2, arg3]),
worker(Cachex, [ worker(
:user_cache, Cachex,
[ [
default_ttl: 25000, :user_cache,
ttl_interval: 1000, [
limit: 2500 default_ttl: 25000,
] ttl_interval: 1000,
]), limit: 2500
]
],
id: :cachex_user
),
worker(
Cachex,
[
:object_cache,
[
default_ttl: 25000,
ttl_interval: 1000,
limit: 2500
]
],
id: :cachex_object
),
worker( worker(
Cachex, Cachex,
[ [

View file

@ -37,7 +37,7 @@ defmodule Pleroma.Object do
else else
key = "object:#{ap_id}" key = "object:#{ap_id}"
Cachex.fetch!(:user_cache, key, fn _ -> Cachex.fetch!(:object_cache, key, fn _ ->
object = get_by_ap_id(ap_id) object = get_by_ap_id(ap_id)
if object do if object do
@ -56,7 +56,7 @@ defmodule Pleroma.Object do
def delete(%Object{data: %{"id" => id}} = object) do def delete(%Object{data: %{"id" => id}} = object) do
with Repo.delete(object), with Repo.delete(object),
Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id)), Repo.delete_all(Activity.all_non_create_by_object_ap_id_q(id)),
{:ok, true} <- Cachex.del(:user_cache, "object:#{id}") do {:ok, true} <- Cachex.del(:object_cache, "object:#{id}") do
{:ok, object} {:ok, object}
end end
end end

View file

@ -42,7 +42,7 @@ defmodule Pleroma.ObjectTest do
Object.delete(cached_object) Object.delete(cached_object)
{:ok, nil} = Cachex.get(:user_cache, "object:#{object.data["id"]}") {:ok, nil} = Cachex.get(:object_cache, "object:#{object.data["id"]}")
cached_object = Object.get_cached_by_ap_id(object.data["id"]) cached_object = Object.get_cached_by_ap_id(object.data["id"])