BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlt::TimetableCache Class Reference

#include <bdlt_timetablecache.h>

Public Member Functions

 TimetableCache (TimetableLoader *loader, bslma::Allocator *basicAllocator=0)
 
 TimetableCache (TimetableLoader *loader, const bsls::TimeInterval &timeout, bslma::Allocator *basicAllocator=0)
 
 ~TimetableCache ()
 Destroy this object.
 
bsl::shared_ptr< const TimetablegetTimetable (const char *timetableName)
 
int invalidate (const char *timetableName)
 
int invalidateAll ()
 
bsl::shared_ptr< const TimetablelookupTimetable (const char *timetableName) const
 
Datetime lookupLoadTime (const char *timetableName) const
 

Detailed Description

This class implements an efficient cache of read-only bdlt::Timetable objects that are loaded into the cache, using a timetable loader supplied at construction, as a side-effect of the getTimetable manipulator. Timetables in the cache can be invalidated, and removed from the cache via the invalidate and invalidateAll methods. In addition, timetables in the cache can be made to expire based on a timeout that may be optionally supplied at construction. The bsl::shared_ptr<const bdlt::Timetable> objects returned from the getTimetable and lookupTimetable methods allow for the safe removal of timetables from the cache that may still have outstanding references to them.

This container is exception neutral with no guarantee of rollback: if an exception is thrown during the invocation of a method on a pre-existing instance, the container is left in a valid state, but its value is undefined. In no event is memory leaked.

This class is fully thread-safe (see bsldoc_glossary ).

See bdlt_timetablecache

Constructor & Destructor Documentation

◆ TimetableCache() [1/2]

bdlt::TimetableCache::TimetableCache ( TimetableLoader loader,
bslma::Allocator basicAllocator = 0 
)
explicit

Create an empty timetable cache that uses the specified loader to load timetables on demand and has no timeout. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used. Timetables loaded into this cache remain valid for retrieval until they have been explicitly invalidated (via either the invalidate or invalidateAll methods), or until this object is destroyed. The behavior is undefined unless loader remains valid throughout the lifetime of this cache.

◆ TimetableCache() [2/2]

bdlt::TimetableCache::TimetableCache ( TimetableLoader loader,
const bsls::TimeInterval timeout,
bslma::Allocator basicAllocator = 0 
)

Create an empty timetable cache that uses the specified loader to load timetables on demand and has the specified timeout interval indicating the length of time that timetables remain valid for subsequent retrieval from the cache after they have been loaded. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used. The behavior is undefined unless bsls::TimeInterval() <= timeout <= bsls::TimeInterval(INT_MAX, 0), and loader remains valid throughout the lifetime of this cache. Note that a timeout value of 0 indicates that a timetable will be loaded into the cache by each (successful) call to the getTimetable method.

◆ ~TimetableCache()

bdlt::TimetableCache::~TimetableCache ( )

Member Function Documentation

◆ getTimetable()

bsl::shared_ptr< const Timetable > bdlt::TimetableCache::getTimetable ( const char *  timetableName)

Return a shared pointer providing non-modifiable access to the timetable having the specified timetableName in this timetable cache, loading the timetable into the cache using the loader that was supplied at construction if the timetable is not already present in the cache or if the timetable has expired (i.e., per a timeout optionally supplied at construction). If the loader fails, whether in loading a timetable for the first time or in reloading a timetable that has expired, return an empty shared pointer.

◆ invalidate()

int bdlt::TimetableCache::invalidate ( const char *  timetableName)

Invalidate the timetable having the specified timetableName in this timetable cache, and remove it from the cache. If a timetable having timetableName is not present in this cache, this method has no effect. Return the number of timetables that were invalidated. Note that a timetable that has been invalidated in the cache remains valid to all outstanding references to it, obtained via earlier calls to the getTimetable and lookupTimetable methods, until all of those references have been destroyed.

◆ invalidateAll()

int bdlt::TimetableCache::invalidateAll ( )

Invalidate all timetables in this timetable cache, and remove them from the cache. Return the number of timetables that were invalidated. Note that a timetable that has been invalidated in the cache remains valid to all outstanding references to it, obtained via earlier calls to the getTimetable and lookupTimetable methods, until all of those references have been destroyed.

◆ lookupLoadTime()

Datetime bdlt::TimetableCache::lookupLoadTime ( const char *  timetableName) const

Return the datetime, in Coordinated Universal Time (UTC), at which the timetable having the specified timetableName was loaded into this timetable cache. If the timetable having timetableName is not found in the cache, or if the timetable has expired (i.e., per a timeout optionally supplied at construction), return Datetime().

◆ lookupTimetable()

bsl::shared_ptr< const Timetable > bdlt::TimetableCache::lookupTimetable ( const char *  timetableName) const

Return a shared pointer providing non-modifiable access to the timetable having the specified timetableName in this timetable cache. If the timetable having timetableName is not found in the cache, or if the timetable has expired (i.e., per a timeout optionally supplied at construction), return an empty shared pointer.


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