{"id":22237547,"url":"https://github.com/emcousin/activemodel-caching","last_synced_at":"2026-01-26T01:02:04.132Z","repository":{"id":262637868,"uuid":"887883933","full_name":"EmCousin/activemodel-caching","owner":"EmCousin","description":"ActiveModel::Caching is a flexible gem for managing temporary data structures (scalars, lists, JSON) using a caching backend, typically Rails cache but adaptable to other solutions. It offers a simple, Rails-friendly API for efficient, transient data handling.","archived":false,"fork":false,"pushed_at":"2024-11-15T17:18:19.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-03T19:48:17.735Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/EmCousin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-11-13T13:00:43.000Z","updated_at":"2024-11-15T17:13:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"d2ffcb77-e7b8-4a56-8872-848d090ad929","html_url":"https://github.com/EmCousin/activemodel-caching","commit_stats":null,"previous_names":["emcousin/activemodel-caching"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/EmCousin/activemodel-caching","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmCousin%2Factivemodel-caching","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmCousin%2Factivemodel-caching/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmCousin%2Factivemodel-caching/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmCousin%2Factivemodel-caching/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EmCousin","download_url":"https://codeload.github.com/EmCousin/activemodel-caching/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmCousin%2Factivemodel-caching/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28763088,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T00:37:26.264Z","status":"ssl_error","status_checked_at":"2026-01-26T00:37:25.959Z","response_time":113,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-12-03T03:11:28.695Z","updated_at":"2026-01-26T01:02:04.108Z","avatar_url":"https://github.com/EmCousin.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActiveModel::Caching\n\nA library providing easy-to-use object-level caching methods for various data types in a Ruby on Rails application, allowing you to cache different attribute types directly on your models.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'activemodel-caching'\n```\n\nThen execute:\n\n```bash\n$ bundle install\n```\n\n## Configuration\n\nConfigure the gem in an initializer:\n\n```ruby\nActiveModel::Caching.setup do |config|\n  config.cache_store = Rails.cache # Defaults to Rails.cache if Rails is defined, otherwise to memory store\n  config.global_id_app = 'MyApp'   # Defaults to GlobalID.app if present, otherwise to Rails.application.name if Rails is defined\nend\n```\n\n## Usage\n\nInclude the module in your class:\n\n```ruby\nclass User\n  include ActiveModel::Caching\n\n  cache_string :session_token\n  cache_integer :view_count\n  # ... etc\nend\n```\n\n## Available Cache Types\n\n### Basic Types\n\n#### `cache_string`\nCaches a string value.\n```ruby\ncache_string :session_token\n# Generates:\n# - session_token\n# - session_token=\n```\n\n#### `cache_integer`\nCaches an integer value.\n```ruby\ncache_integer :view_count\n# Generates:\n# - view_count\n# - view_count=\n```\n\n#### `cache_decimal`\nCaches a decimal value.\n```ruby\ncache_decimal :account_balance\n# Generates:\n# - account_balance\n# - account_balance=\n```\n\n#### `cache_datetime`\nCaches a datetime value.\n```ruby\ncache_datetime :last_login\n# Generates:\n# - last_login\n# - last_login=\n```\n\n#### `cache_flag` / `cache_boolean`\nCaches a boolean value.\n```ruby\ncache_flag :is_active\n# or\ncache_boolean :is_verified\n# Generates:\n# - is_active\n# - is_active=\n```\n\n#### `cache_float`\nCaches a float value.\n```ruby\ncache_float :average_rating\n# Generates:\n# - average_rating\n# - average_rating=\n```\n\n### Complex Types\n\n#### `cache_enum`\nCaches an enum value, storing the value among defined options.\n```ruby\ncache_enum :status, %w[active inactive suspended]\n# Generates:\n# - status\n# - status=\n```\n\n#### `cache_json`\nCaches a JSON value.\n```ruby\ncache_json :user_preferences\n# Generates:\n# - user_preferences\n# - user_preferences=\n```\n\n#### `cache_hash`\nCaches a hash value.\n```ruby\ncache_hash :settings\n# Generates:\n# - settings\n# - settings=\n```\n\n### Collections\n\n#### `cache_list`\nCaches an ordered list of values, maintaining order and optional limit.\n```ruby\ncache_list :recent_posts, limit: 5\n# Generates:\n# - recent_posts\n# - add_to_recent_posts\n# - remove_from_recent_posts\n```\n\n#### `cache_unique_list`\nCaches a unique list of values, maintaining uniqueness and optional limit.\n```ruby\ncache_unique_list :favorite_articles, limit: 10\n# Generates:\n# - favorite_articles\n# - add_to_favorite_articles\n# - remove_from_favorite_articles\n```\n\n#### `cache_set`\nCaches a set of unique values with optional limit.\n```ruby\ncache_set :tags, limit: 5\n# Generates:\n# - tags\n# - add_to_tags\n# - remove_from_tags\n```\n\n#### `cache_ordered_set`\nCaches an ordered set of values, maintaining order and optional limit.\n```ruby\ncache_ordered_set :recent_views, limit: 10\n# Generates:\n# - recent_views\n# - add_to_recent_views\n# - remove_from_recent_views\n```\n\n### Special Types\n\n#### `cache_slots`\nCaches a limited number of available \"slots\" for resources like seats or reservations.\n```ruby\ncache_slots :seats, available: 10\n# Generates:\n# - seats\n# - available_seats?\n# - reserve_seats!\n# - release_seats!\n# - reset_seats!\n```\n\n#### `cache_slot`\nCaches a single slot (binary available/taken resource).\n```ruby\ncache_slot :parking_space\n# Generates:\n# - parking_space\n# - available_parking_space?\n# - reserve_parking_space!\n# - release_parking_space!\n# - reset_parking_space!\n```\n\n#### `cache_counter`\nCaches a counter value.\n```ruby\ncache_counter :likes_count\n# Generates:\n# - likes_count\n# - increment_likes_count\n# - decrement_likes_count\n# - reset_likes_count\n```\n\n#### `cache_limiter`\nCaches a limiter value with a maximum allowed count.\n```ruby\ncache_limiter :api_requests, limit: 100\n# Generates:\n# - api_requests\n# - increment_api_requests\n# - reset_api_requests\n```\n\n## Options\n\nAll cache methods accept an optional `expires_in` parameter:\n\n```ruby\ncache_string :session_token, expires_in: 1.hour\ncache_counter :daily_visits, expires_in: 1.day\n```\n\n## Contributing\n\nBug reports and pull requests are welcome at https://github.com/EmCousin/activemodel-caching.\n\n## License\n\nThis gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femcousin%2Factivemodel-caching","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femcousin%2Factivemodel-caching","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femcousin%2Factivemodel-caching/lists"}