The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Alzabo::ObjectCache::Sync - Base class for syncing classes

SYNOPSIS

  package Alzabo::ObjectCache::TelepathySync;
  use base qw( Alzabo::ObjectCache::Sync );

DESCRIPTION

This class implements most of the logic needed for syncing operations. Subclasses only need to implement methods for actually storing and retrieving the refresh times for an object.

METHODS

new

Returns

A new cache object.

fetch_object ($id)

Returns

The object if it is in the cache. Otherwise it returns undef.

store_object ($object)

Stores an object in the cache. This will not overwrite an existing object in the cache. To do that you must first call the delete_from_cache method.

is_expired ($object)

An object is expired when the local copy's last retrieval of its data occurred before another copy (in another process, presumably) updated the external data source containing the object's data (such as an RDBMS). Note that a deleted object will not be reported as expired. Instead, call the is_deleted method.

Returns

A boolean value indicating whether or not the object is expired.

is_deleted ($object)

Returns

A boolean value indicating whether or not an object has been deleted from the cache.

register_refresh ($object)

This tells the cache that an object considers its internal data to be up to date with whatever external source it needs to be up to date with.

register_change ($object)

This tells the cache that an object has updated its external data source. This means that objects in other processes now become expired.

register_delete ($object)

This tells the cache that the object has been removed from its external data source. This causes the cache to remove the object internally. Future calls to is_deleted in any process for this object will now return true.

delete_from_cache ($object)

This method allows you to remove an object from the cache. This does not register the object as deleted. It is provided solely so that you can call store_object after calling this method and have store_object actually store the new object.

VIRTUAL METHODS

The following methods should be implemented in a subclass.

_init

This method will be called when the object is first created. If not implemented then it will be a noop.

sync_time ($id)

Returns

Returns the time that the object matching the given id was last refreshed.

update ($id, $time, $overwrite)

This is called to update the state of the syncing object in regards to a particularl object. The first parameter is the object's id. The second is the time that the object was last refreshed. The third parameter, which is optional, tells the syncing object whether or not to preserve an existing time for the object if it already has one.

AUTHOR

Dave Rolsky, <autarch@urth.org>