{"id":15699964,"url":"https://github.com/nsweeting/stat_buffer","last_synced_at":"2025-05-12T13:03:40.178Z","repository":{"id":57552938,"uuid":"131435386","full_name":"nsweeting/stat_buffer","owner":"nsweeting","description":"StatBuffer provides an efficient way to maintain persistable stat counts.","archived":false,"fork":false,"pushed_at":"2020-01-25T20:35:06.000Z","size":46,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-29T11:44:04.351Z","etag":null,"topics":["buffer","counter","elixir","ets","phoenix","stats"],"latest_commit_sha":null,"homepage":"","language":"Elixir","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/nsweeting.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":"2018-04-28T18:45:20.000Z","updated_at":"2023-01-13T23:13:19.000Z","dependencies_parsed_at":"2022-09-26T18:50:55.185Z","dependency_job_id":null,"html_url":"https://github.com/nsweeting/stat_buffer","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsweeting%2Fstat_buffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsweeting%2Fstat_buffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsweeting%2Fstat_buffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsweeting%2Fstat_buffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nsweeting","download_url":"https://codeload.github.com/nsweeting/stat_buffer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253745051,"owners_count":21957316,"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":["buffer","counter","elixir","ets","phoenix","stats"],"created_at":"2024-10-03T19:43:17.774Z","updated_at":"2025-05-12T13:03:40.027Z","avatar_url":"https://github.com/nsweeting.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# StatBuffer\n\n[![Build Status](https://travis-ci.org/nsweeting/stat_buffer.svg?branch=master)](https://travis-ci.org/nsweeting/stat_buffer)\n[![StatBuffer Version](https://img.shields.io/hexpm/v/stat_buffer.svg)](https://hex.pm/packages/stat_buffer)\n\nStatBuffer is an efficient way to maintain a local incrementable count with a given key that can later be flushed to persistent storage. In fast moving systems, this provides a scalable way keep track of counts without putting heavy loads on a database.\n\n## Installation\n\nThe package can be installed by adding `stat_buffer` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:stat_buffer, \"~\u003e 1.2\"}\n  ]\nend\n```\n\n## Documentation\n\nPlease see [HexDocs](https://hexdocs.pm/stat_buffer/StatBuffer.html#content) for additional documentation. This readme provides a brief overview, but it is recommended that the docs are used.\n\n## Creating a Buffer\n\nWe can start off by creating our buffer. This is simply a module that uses `StatBuffer`\nand implements the `handle_flush/2` callback.\n\n```elixir\ndefmodule Buffer do\n  use StatBuffer\n\n  def handle_flush(key, counter) do\n    # do database stuff...\n\n    # we must return an :ok atom\n    :ok\n  end\nend\n```\n\nWe then must add the buffer to our supervision tree.\n\n```elixir\nchildren = [\n  Buffer\n]\n```\n\nThere are some configruable options available for our buffers. You can read more about them [here](https://hexdocs.pm/stat_buffer/StatBuffer.html#module-options). These options can be passed when creating our buffer.\n\n```elixir\n  use StatBuffer, interval: 10_000\n```\n\nWith our buffer started, we can now increment key counters. A key can be any valid term.\n\n```elixir\nBuffer.increment(\"mykey\") # increments by 1\n\nBuffer.increment(\"mykey\", 10) # increments by 10\n```\n\nAnd we're done! Our counter will be flushed using our `handle_flush/2` callback\nafter the default interval period. Dead counters are automatically removed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsweeting%2Fstat_buffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnsweeting%2Fstat_buffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsweeting%2Fstat_buffer/lists"}