{"id":17159654,"url":"https://github.com/schmidt/cache_annotations","last_synced_at":"2025-03-24T15:08:34.469Z","repository":{"id":743443,"uuid":"394703","full_name":"schmidt/cache_annotations","owner":"schmidt","description":"old experiment to implement active_support's memoize before a_s came up with it","archived":false,"fork":false,"pushed_at":"2009-12-03T23:01:15.000Z","size":92,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-02T10:46:44.213Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/schmidt.png","metadata":{"files":{"readme":"README.rdoc","changelog":"History.txt","contributing":null,"funding":null,"license":"License.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2009-12-03T22:41:21.000Z","updated_at":"2014-02-25T05:05:07.000Z","dependencies_parsed_at":"2022-08-16T10:45:27.319Z","dependency_job_id":null,"html_url":"https://github.com/schmidt/cache_annotations","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schmidt%2Fcache_annotations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schmidt%2Fcache_annotations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schmidt%2Fcache_annotations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schmidt%2Fcache_annotations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/schmidt","download_url":"https://codeload.github.com/schmidt/cache_annotations/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245294768,"owners_count":20591900,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T22:14:48.496Z","updated_at":"2025-03-24T15:08:34.447Z","avatar_url":"https://github.com/schmidt.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"With CacheAnnotation you may easily provide your methods with an often needed\ncaching. Suppose you are using the following piece of code:\n\n  class A\n    def a\n      @a ||= \"some heavy computing that should be done only once\"\n    end\n  end\n\nThis could look so much better:\n\n  class A\n    include CacheAnnotation\n\n    cached\n    def a\n      \"some heavy computing that should be done only once\"\n    end\n  end\n\nOr even better for single argumented methods:\n\n  class A\n    def b(arg0)\n      @b ||= {}\n      @b[arg0] ||= \"some heavy computing in respect to #{arg0} \" + \n                   \"that should be done only once\"\n    end\n  end\n\nvs.\n\n  class A\n    include CacheAnnotation\n\n    cached\n    def b(arg0)\n      \"some heavy computing in respect to #{arg0} \" + \n      \"that should be done only once\"\n    end\n  end\n\nBehind the scenes, CacheAnnotation replaces the method body with the caching\ncode. So the two versions are equal concerning behaviour and speed. If you\ndon't want CacheAnnotation to derive the instance variable's name from the \nmethod name, you may supply a custom one:\n\n  class A\n    include CacheAnnotation\n\n    cached :in =\u003e :@b_cache\n    def b(arg0)\n      \"some heavy computing in respect to #{arg0} \" + \n      \"that should be done only once\"\n    end\n  end\n\nIf you want to use CacheAnnotation on the class side, you have to use a \nspecial technique to add these methods. It is described pretty good on \nhttp://www.dcmanges.com/blog/27\n\n  class A\n    module ClassMethods\n      include CacheAnnotation\n\n      cached\n      def c\n        \"some heavy computing that should be done only once\"\n      end\n    end\n    self.extend(ClassMethods)\n  end\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschmidt%2Fcache_annotations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fschmidt%2Fcache_annotations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschmidt%2Fcache_annotations/lists"}