Skip to content

Commit

Permalink
Merge pull request #57 from AlgebraicJulia/cache_name
Browse files Browse the repository at this point in the history
cached filename changes when schema changes
  • Loading branch information
kris-brown authored May 10, 2024
2 parents 677ff82 + af4a30d commit 7e2cde3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/literate/lotka_volterra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ macro is perfect for exactly this. In order to use
that macro, we need to compute something first with the `yoneda_cache` function.
=#

yLV = yoneda_cache(LV; clear=true); # reuse cached result, if available
yLV = yoneda_cache(LV; clear=false); # cache=false means reuse cached results
I = LV() # Empty agent type
S = @acset_colim yLV begin s::Sheep end # Generic sheep agent
W = F(S) # Generic wolf agent, obtained via the swapping `F` data migration
Expand Down
8 changes: 7 additions & 1 deletion src/rewrite/Migration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ end
# Caching
#########

"""
Want a filename that is stable to multiple Julia sessions but changes when the
schema changes. This minimizes the need to clear the cache.
"""
pres_hash(p::Presentation) = "$(hash(p.generators))_$(hash(p.equations))"

function yoneda_cache(T::Type,S=nothing; clear=false, cache="cache")
S = isnothing(S) ? Presentation(T) : S
tname = nameof(T) |> string
tname = "$(nameof(T))_$(pres_hash(S))"
cache_dict = Dict{Symbol,Tuple{T,Int}}(map(generators(S, :Ob)) do ob
name = nameof(ob)
cache_dir = mkpath(joinpath(cache, "$tname"))
Expand Down

0 comments on commit 7e2cde3

Please sign in to comment.