{"id":19139895,"url":"https://github.com/arcblock/mcc","last_synced_at":"2025-07-16T01:34:02.110Z","repository":{"id":57521976,"uuid":"167313539","full_name":"ArcBlock/mcc","owner":"ArcBlock","description":"Cache built via mnesia which support expiration and cluster. (mcc is \"mnesia cluster cache\")","archived":false,"fork":false,"pushed_at":"2019-08-15T14:08:17.000Z","size":65,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-05-06T23:14:49.370Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ArcBlock.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-24T06:12:49.000Z","updated_at":"2023-09-01T10:49:48.000Z","dependencies_parsed_at":"2022-08-26T20:23:32.617Z","dependency_job_id":null,"html_url":"https://github.com/ArcBlock/mcc","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArcBlock%2Fmcc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArcBlock%2Fmcc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArcBlock%2Fmcc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArcBlock%2Fmcc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ArcBlock","download_url":"https://codeload.github.com/ArcBlock/mcc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252782834,"owners_count":21803410,"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-11-09T07:15:36.755Z","updated_at":"2025-05-06T23:14:54.777Z","avatar_url":"https://github.com/ArcBlock.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mcc (Mnesia Cluster Cache)\n\n[![Build Status](https://travis-ci.com/ArcBlock/mcc.svg?token=y7spFnxztFEypxKZdeqR\u0026branch=master)](https://travis-ci.com/ArcBlock/mcc)\n[![Hex.pm Version](https://img.shields.io/hexpm/v/mcc.svg?style=flat-square)](https://hex.pm/packages/mcc)\n\n`mcc` is Mnesia Cluster Cache, which support expiration and cluster.\n\n## usage\n\nThere are some steps to use mcc:\n\n  - define table\n  - define model\n  - start expiration process\n\n### define table\n\nMcc support expiration and each table need one assistant table to store expiration information.\n\n```elixir\n  use Mcc.Model.Table,\n    table_opts: [\n      type: :set,\n      ram_copies: [node()],\n      storage_properties: [\n        ets: [:compressed, read_concurrency: true]\n      ]\n    ],\n    expiration_opts: [\n      expiration_table: AccountExp,\n      main_table: MccTest.Support.Table.Account,\n      size_limit: 100,\n      # 300M\n      memory_limit: 300\n    ]\n\n  defstruct([:id, :user_profile], true)\n```\n\nLike above table definition, the `table_opts` is from [mnesia create table](http://erlang.org/doc/man/mnesia.html#create_table-2). And `expiration_opts` has several option:\n\n- expiration_table\n  which table to store expiration information\n\n- main_table\n  current table\n\n- size_limit\n  the table size limit\n\n- memory_limit\n  the memory usage limit, unit is `mega byte`\n\nAfter define the table, need define the fields for the table, user can use `defstruct/1,2` to define the table's fields. Multi-fields use `[]` to organize, and fields should use `atom`. The second parameter for `defstruct` is represent if use cache expiration mechanism.\n\nFor the assistant table, the definition will be like:\n\n```elixir\ndefmodule MccTest.Support.Table.Account.Exp do\n  @moduledoc \"\"\"\n  Table for expiration Account table.\n  \"\"\"\n\n  use Mcc.Model.Table,\n    table_opts: [\n      type: :ordered_set,\n      ram_copies: [node()],\n      storage_properties: [\n        ets: [:compressed, read_concurrency: true]\n      ]\n    ]\n\n  defstruct [:key, :value]\n\n  def put(key, value) do\n    put(%__MODULE__{key: key, value: value})\n  end\nend\n```\n\n## define model\n\nAfter define table, user need to define model, it's not difficult:\n\n```elixir\ndefmodule MccTest.Support.Cache do\n  @moduledoc \"\"\"\n  Definition for cache test.\n  \"\"\"\n\n  use Mcc.Model\n\n  import_table(MccTest.Support.Table.Account.Exp)\n  import_table(MccTest.Support.Table.Account)\nend\n```\n\ndefine model is import the tables which defined before.\n\n## start expiration process\n\n`mcc` use one long-lived process to scan the mnesia table for expiration. User(application) need to start the process explicitly:\n\n```elixir\nMccTest.Support.Cache.start_expiration_process()\n```\n\nGenerally speaking, it will be put into application start.\n\n[One complete example could be found in the test cases]\n\n## Change log\n\n- [v1.0.1]\n  - Fixed bug when put with ttl and remove `delete_object/1`\n\n\n  [pull request](https://github.com/ArcBlock/mcc/pull/6)\n\n- [v1.0.2]\n  - try to connect kernel optional nodes before join cluster\n  - added log after joined in cluster and create/copy table\n\n  [pull request](https://github.com/ArcBlock/mcc/pull/7)\n\n- [v1.0.3]\n  - support different level for operation consistency\n  - remove `delete/2` function, will delete expiration table automatically\n  - need not pass `cache_time` when put record, will calculate `now` real-time\n\n  FYI: [operation consistency for Mnesia](http://erlang.org/doc/apps/mnesia/Mnesia_chap4.html)\n\n  [pull request](https://github.com/ArcBlock/mcc/pull/8)\n\n- [v1.1.0]\n  - support split mcc cluster from the logic service\n  - added two examples to present how to use mcc\n\n  pull requests:\n\n    - https://github.com/ArcBlock/mcc/pull/12\n    - https://github.com/ArcBlock/mcc/pull/5\n    - https://github.com/ArcBlock/mcc/pull/10\n    - https://github.com/ArcBlock/mcc/pull/9\n    - https://github.com/ArcBlock/mcc/pull/11\n\n  closed issues:\n\n    - https://github.com/ArcBlock/mcc/issues/4\n\n- [v1.1.1]\n  - support async put through writer process\n\n  [pull request](https://github.com/ArcBlock/mcc/pull/13)\n\n- [v1.2.0]\n  - support dynamic table\n\n  [pull request](https://github.com/ArcBlock/mcc/pull/14)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farcblock%2Fmcc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farcblock%2Fmcc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farcblock%2Fmcc/lists"}