CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Sun, 31 Aug 2025 10:05:04 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20080916110736
location: https://web.archive.org/web/20080916110736/https://github.com/vigetlabs/constant_cache/tree
server-timing: captures_list;dur=1.406197, exclusion.robots;dur=0.056524, exclusion.robots.policy;dur=0.034303, esindex;dur=0.019192, cdx.remote;dur=24.799933, LoadShardBlock;dur=334.629317, PetaboxLoader3.datanode;dur=81.720261, PetaboxLoader3.resolve;dur=85.721875
x-app-server: wwwb-app202
x-ts: 302
x-tr: 565
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: wb-p-SERVER=wwwb-app202; path=/
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 302
server: nginx
date: Sun, 31 Aug 2025 10:05:05 GMT
content-type: text/html; charset=utf-8
content-length: 120
x-archive-orig-server: nginx/0.6.31
x-archive-orig-date: Tue, 16 Sep 2008 11:07:34 GMT
x-archive-orig-connection: close
x-archive-orig-status: 302 Found
location: https://web.archive.org/web/20080916110736/https://github.com/vigetlabs/constant_cache/tree/master
x-archive-orig-x-runtime: 0.17677
x-archive-orig-cache-control: no-cache
x-archive-orig-content-length: 120
cache-control: max-age=1800
memento-datetime: Tue, 16 Sep 2008 11:07:36 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Tue, 15 Apr 2008 03:56:00 GMT", ; rel="prev memento"; datetime="Sat, 26 Jul 2008 03:37:51 GMT", ; rel="memento"; datetime="Tue, 16 Sep 2008 11:07:36 GMT", ; rel="next memento"; datetime="Tue, 16 Dec 2008 01:50:13 GMT", ; rel="last memento"; datetime="Sat, 29 Sep 2012 12:14:51 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: 52_5_20080916084933_crawl109-c/52_5_20080916110534_crawl103.arc.gz
server-timing: captures_list;dur=0.568409, exclusion.robots;dur=0.028002, exclusion.robots.policy;dur=0.016574, esindex;dur=0.010972, cdx.remote;dur=11.909873, LoadShardBlock;dur=119.414157, PetaboxLoader3.datanode;dur=181.626097, PetaboxLoader3.resolve;dur=137.089168, load_resource;dur=235.694637
x-app-server: wwwb-app202
x-ts: 302
x-tr: 397
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=1
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 200
server: nginx
date: Sun, 31 Aug 2025 10:05:06 GMT
content-type: text/html; charset=utf-8
x-archive-orig-server: nginx/0.6.31
x-archive-orig-date: Tue, 16 Sep 2008 11:07:35 GMT
x-archive-orig-connection: close
x-archive-orig-status: 200 OK
x-archive-orig-x-runtime: 0.86911
x-archive-orig-etag: "f35ffb6790f6f06b198675dbc9f554bc"
x-archive-orig-cache-control: private, max-age=0, must-revalidate
x-archive-orig-content-length: 16862
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Tue, 16 Sep 2008 11:07:36 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Tue, 15 Apr 2008 03:56:00 GMT", ; rel="prev memento"; datetime="Mon, 23 Jun 2008 04:41:48 GMT", ; rel="memento"; datetime="Tue, 16 Sep 2008 11:07:36 GMT", ; rel="next memento"; datetime="Tue, 16 Dec 2008 01:50:13 GMT", ; rel="last memento"; datetime="Sun, 13 Apr 2014 10:57:42 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: 52_5_20080916084933_crawl109-c/52_5_20080916110534_crawl103.arc.gz
server-timing: captures_list;dur=0.527491, exclusion.robots;dur=0.026474, exclusion.robots.policy;dur=0.016113, esindex;dur=0.010559, cdx.remote;dur=10.328864, LoadShardBlock;dur=294.244220, PetaboxLoader3.resolve;dur=249.456448, PetaboxLoader3.datanode;dur=97.784281, load_resource;dur=83.315533
x-app-server: wwwb-app202
x-ts: 200
x-tr: 467
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
content-encoding: gzip
vigetlabs's constant_cache at master — GitHub
This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (

This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (

Description: | Allows the caching of lookup data in your Rails models |
Clone URL: |
git://github.com/vigetlabs/constant_cache.git
Give this clone URL to anyone.
git clone git://github.com/vigetlabs/constant_cache.git
|
Search Repo: |
name | age | message | |
---|---|---|---|
![]() |
.gitignore | Mon Apr 14 22:41:42 -0700 2008 | Improved documentation [reagent] |
![]() |
HISTORY | Mon Apr 14 22:53:32 -0700 2008 | Fix release date [reagent] |
![]() |
MIT-LICENSE | Mon Jun 25 21:11:51 -0700 2007 | Start of constant_cache plugin (for Advanced Ra... [reagent] |
![]() |
README | Mon Apr 14 22:41:42 -0700 2008 | Improved documentation [reagent] |
![]() |
Rakefile | Mon Apr 14 22:43:12 -0700 2008 | Minor change to description [reagent] |
![]() |
lib/ | Mon Apr 14 22:41:42 -0700 2008 | Improved documentation [reagent] |
![]() |
spec/ | Mon Apr 14 22:41:42 -0700 2008 | Improved documentation [reagent] |
README
= Constant Cache When your database has tables that store lookup data, there is a tendency to provide those values as constants in the model. If you have an account_statuses table with a corresponding model, your constants may look like this: class AccountStatus ACTIVE = 1 PENDING = 2 DISABLED = 3 end There are a couple of problems with this approach: As you add more lookup data to the table, you need to ensure that you're updating your models along with the data. The constants are stored as integer values and need to match up exactly with the data that's in the table (not necessarily a bad thing), but this solution forces you to write code like this: Account.new(:username => 'preagan', :status => AccountStatus.find(AccountStatus::PENDING)) This requires multiple calls to find and obfuscates the code a bit. Since classes in Ruby are executable code, we can cache the objects from the database at runtime and use them in your application. == Installation This code is packaged as a gem, so simply use the `gem` command to install: gem install constant_cache == Example "Out of the box," the constant_cache gem assumes that you want to use the 'name' column to generate constants from a column called 'name' in your database table. Assuming this schema: create_table :account_statuses do |t| t.string :name, :description end AccountStatus.create!(:name => 'Active', :description => 'Active user account') AccountStatus.create!(:name => 'Pending', :description => 'Pending user account') AccountStatus.create!(:name => 'Disabled', :description => 'Disabled user account') We can use the plugin to cache the data in the table: class AccountStatus caches_constants end Now you can write code that's a little cleaner and not use multiple unnecessary find calls: Account.new(:username => 'preagan', :status => AccountStatus::PENDING) If the column you want to use as the constant isn't 'name', you can set that in the model. If we have :name, :slug, and :description, we can use 'slug' instead: class AccountStatus caches_constants :key => :slug end The value for the constant is truncated at 64 characters by default, but you can adjust this as well: class AccountStatus caches_constants :limit => 16 end == Acknowlegements Thanks to Dave Thomas for inspiring me to write this during his Metaprogramming talk at a Rails Edge conference in early 2007. Copyright (c) 2007 Patrick Reagan of Viget Labs (mailto:patrick.reagan@viget.com), released under the MIT license
This feature is coming soon. Sit tight!