2017 © Pedro PelĆ”ez
 

library php-proxy

Proxy utilities (i.e. caching proxy)

image

mz/php-proxy

Proxy utilities (i.e. caching proxy)

  • Tuesday, August 5, 2014
  • by m-zajac
  • Repository
  • 1 Watchers
  • 0 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

PHP proxy

This library provides proxy classes with easily extendable behavior. Library includes ready for use caching proxy and lazy instantiation proxy., (*1)

Requirements and dependencies

This library has no external dependencies, if installed with --no-dev option. Caching behavior memcache backend requires php memcache module to be enabled., (*2)

Installation

php composer.phar require mz/php-proxy

Basic usage

In-memory cache proxy

use MZ\Proxy\Shortcuts;

// object proxy
$object = new MyComplexClass();
$proxy = Shortcuts\wrapWithMemoryProxy($object, 5); // 5 seconds timeout (default = 0 - infinite)
$proxy->foo();  // executes foo, stores result in cache
$proxy->foo();  // returns cached result, real foo method is not executed
$proxy->bar();  // works here too
$property = $proxy->my_property  // exactly as $object->my_property
$proxy->my_property = 123; // exactly as $object->my_property = 123

// set cached methods
$proxy->proxySetMethods(array('foo', 'bar'));
$proxy->foo();  // cached
$proxy->bar();  // cached
$proxy->baz();  // not cached

$proxy->proxySetMethods(null); // all methods cached fro this point (default)

$callable = function() {
    // some time intensive code...
};
$proxy = Shortcuts\wrapWithMemoryProxy($callable);
$result = $proxy();  // executes function
$result = $proxy();  // returns cached result

Cache proxy with memcache

use MZ\Proxy\Shortcuts;

$object = new MyComplexClass();

$memcache = new \Memcache();
$memcache->addServer('localhost', 11211);

$proxy = Shortcuts\wrapWithMemcacheProxy(
    $object,
    'memcache_prefix',
    $memcache
);

$result = $proxy->foo();  // executes foo
$result = $proxy->foo();  // returns cached result, real foo method is not executed

Concepts

class diagram, (*3)

Extending proxy behavior

TODO, (*4)

Limitations

Proxies do not implement subjects interface., (*5)

Examples

TODO, (*6)

The Versions

05/08 2014

dev-master

9999999-dev https://github.com/m-zajac/php-proxy

Proxy utilities (i.e. caching proxy)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Maciek Zając

cache proxy caching proxy

19/07 2014

0.2

0.2.0.0 https://github.com/m-zajac/php-proxy

Proxy utilities (i.e. caching proxy)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Maciek Zając

cache proxy caching proxy

18/07 2014

0.1.1

0.1.1.0 https://github.com/m-zajac/php-proxy

Proxy utilities (i.e. caching proxy)

  Sources   Download

The Requires

  • php >=5.3.0

 

The Development Requires

by Maciek Zając

cache proxy caching proxy

18/07 2014

0.1

0.1.0.0 https://github.com/m-zajac/php-proxy

Proxy utilities (i.e. caching proxy)

  Sources   Download

The Requires

  • php >=5.3.0

 

The Development Requires

by Maciek Zając

cache proxy caching proxy