3 ms·
Simple question. According to [1], middlewares are cloned for each request. Is there a good built-in way of accessing shared mutable data, such as a connection
by mercurial 12y ago
Simple question. According to [1], middlewares are cloned for each request. Is there a good built-in way of accessing shared mutable data, such as a connection pool?
1: http://docs.ironframework.io/iron/trait.Middleware.html http://docs.ironframework.io/iron/trait.Middleware.html
- jonreem 12y agoYou are looking for https://github.com/iron/persistent https://github.com/iron/persistent, which offers two utility middleware for exactly this.
- mercurial 12y agoVery nice, thanks.
- zzmp 12y agoWe have a middleware for that! You can look at http://github.com/iron/persistent http://github.com/iron/persistent, which does wrap an RWLock in an Arc. It also provides a struct to make your middleware Share, so you can do similar things. We also have session, which works on a HashMap under an Arc, although it isolates the mutable data to a session, instead of sharing it across isolated requests.
- eddyb 12y agoI would guess `Arc<Mutex<T>>`, `Arc<RWLock<T>>` and `Arc<SomeConcurrentContainer>` would all work (cloning them is a ref-count - the handle gets copied, not the contents).