Skip to content

Instantly share code, notes, and snippets.

@Ke-
Last active May 9, 2016 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ke-/5a631f50eb5366b9cc35 to your computer and use it in GitHub Desktop.
Save Ke-/5a631f50eb5366b9cc35 to your computer and use it in GitHub Desktop.
Used either for a singleton effect or just for performance.
// Cache method result on a thread level
define cache_method(c::capture = givenblock) => {
#c->isnota(::capture) ? return #c
local(v) = #c->self ? #c->self->type->asstring + '.' + #c->methodname | #c->methodname
var(#v)->isa(::null) ? var(#v) = #c->detach & invoke
return var(#v)
}
@Ke-
Copy link
Author

Ke- commented Jan 22, 2015

define current_user => cache_method => {
return user(session->val(::user_id) || 0)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment