proxygen
folly::IOObjectCache< T > Class Template Reference

#include <IOObjectCache.h>

Public Types

typedef std::function< std::shared_ptr< T >folly::EventBase *)> TFactory
 

Public Member Functions

 IOObjectCache ()=default
 
 IOObjectCache (TFactory factory)
 
std::shared_ptr< Tget ()
 
void setFactory (TFactory factory)
 

Private Attributes

folly::ThreadLocal< std::map< folly::EventBase *, std::shared_ptr< T > > > cache_
 
TFactory factory_
 

Detailed Description

template<class T>
class folly::IOObjectCache< T >

Definition at line 44 of file IOObjectCache.h.

Member Typedef Documentation

template<class T >
typedef std::function<std::shared_ptr<T>folly::EventBase*)> folly::IOObjectCache< T >::TFactory

Definition at line 46 of file IOObjectCache.h.

Constructor & Destructor Documentation

template<class T >
folly::IOObjectCache< T >::IOObjectCache ( )
default
template<class T >
folly::IOObjectCache< T >::IOObjectCache ( TFactory  factory)
inlineexplicit

Definition at line 49 of file IOObjectCache.h.

49 : factory_(std::move(factory)) {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567

Member Function Documentation

template<class T >
std::shared_ptr<T> folly::IOObjectCache< T >::get ( )
inline

Definition at line 51 of file IOObjectCache.h.

References folly::IOObjectCache< T >::cache_, folly::IOObjectCache< T >::factory_, and folly::getIOExecutor().

51  {
52  CHECK(factory_);
53  auto eb = getIOExecutor()->getEventBase();
54  CHECK(eb);
55  auto it = cache_->find(eb);
56  if (it == cache_->end()) {
57  auto p = cache_->insert(std::make_pair(eb, factory_(eb)));
58  it = p.first;
59  }
60  return it->second;
61  };
folly::ThreadLocal< std::map< folly::EventBase *, std::shared_ptr< T > > > cache_
Definition: IOObjectCache.h:68
std::shared_ptr< IOExecutor > getIOExecutor()
template<class T >
void folly::IOObjectCache< T >::setFactory ( TFactory  factory)
inline

Definition at line 63 of file IOObjectCache.h.

References folly::IOObjectCache< T >::factory_, and folly::gen::move.

63  {
64  factory_ = std::move(factory);
65  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567

Member Data Documentation

template<class T >
folly::ThreadLocal<std::map<folly::EventBase*, std::shared_ptr<T> > > folly::IOObjectCache< T >::cache_
private

Definition at line 68 of file IOObjectCache.h.

Referenced by folly::IOObjectCache< T >::get().

template<class T >
TFactory folly::IOObjectCache< T >::factory_
private

The documentation for this class was generated from the following file: