request_with_cache.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Jaeger <JaegerCode@gmail.com>
  5. * Date: 18/12/11
  6. * Time: 下午6:48
  7. */
  8. require __DIR__.'/../vendor/autoload.php';
  9. use Jaeger\GHttp;
  10. use Symfony\Component\Cache\Adapter\RedisAdapter;
  11. $rt = GHttp::get('http://httpbin.org/get',[
  12. 'wd' => 'QueryList'
  13. ],[
  14. 'cache' => __DIR__.DIRECTORY_SEPARATOR.'.cache',
  15. 'cache_ttl' => 120
  16. ]);
  17. print_r($rt);
  18. $cache = new RedisAdapter(
  19. // the object that stores a valid connection to your Redis system
  20. $redis = RedisAdapter::createConnection(
  21. 'redis://localhost'
  22. ),
  23. // the string prefixed to the keys of the items stored in this cache
  24. $namespace = 'cache',
  25. // the default lifetime (in seconds) for cache items that do not define their
  26. // own lifetime, with a value 0 causing items to be stored indefinitely (i.e.
  27. // until RedisAdapter::clear() is invoked or the server(s) are purged)
  28. $defaultLifetime = 0
  29. );
  30. $rt = GHttp::get('http://httpbin.org/get',[
  31. 'wd' => 'QueryList'
  32. ],[
  33. 'cache' => $cache,
  34. 'cache_ttl' => 120
  35. ]);
  36. print_r($rt);