No commit activity in last 3 years
No release in over 3 years
Basic identity map for Ohm.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
 Project Readme

Ohm::IdentityMap

Provides a basic identity map for Ohm.

Usage

require "ohm/identity_map"

# By default, no identity map is used.

Post[1].object_id == Post[1].object_id
# => false

# Enable the identity map for the duration of a block.

Ohm::Model.identity_map do
  Post[1].object_id == Post[1].object_id
end
# => true

Web

It's easy to create a Rack middleware to enable the identity map for the duration of the request/response cycle. (Such middleware may be included in this library in the future, once we test this behavior in production.)

class OhmIdentityMapMiddleware
  def initialize(app)
    @app = app
  end

  def call(env)
    Ohm::Model.identity_map { @app.call(env) }
  end
end

# config.ru or any Rack::Builder
use OhmIdentityMapMiddleware

Known issues

Currently not handling updates and deletes.

License

See UNLICENSE. With love, from Educabilia.