npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-briefcache

v1.3.2

Published

Cache factory for Angular with short expirations

Downloads

10

Readme

angular-briefcache

Cache factory for Angular with short expirations. Designed for preventing duplication of HTTP requests caused by rapid-fire processes, such as running through routing states.

Usage

Use it anywhere you would use Angular's $cacheFactory:

angular.module('myApp', ['banno.briefCache']).service('ExampleService', function($http, briefCache) {
  return {
    find: function() {
      return $http.get('/api/example', { cache: briefCache });
    }
  };
});

Installation

The briefCache requires Angular and the angular-cache library. These are installed automatically when using npm:

`npm install --save angular-briefcache`

Then include the necessary scripts in your app:

<html ng-app="myApp">
  <head>
    <title>Example</title>
    <script src="node_modules/angular/angular.js"></script>
    <script src="node_modules/angular-cache/dist/angular-cache.js"></script>
    <script src="node_modules/angular-briefcache/dist/angular-briefcache.js"></script>
    <script>
      angular.module('myApp', ['banno.briefCache']).run(function(briefCache) {
        console.log('briefCache info:', briefCache.info());
      });
    </script>
  </head>
  <body>Example</body>
</html>

You can also use RequireJS to load the modules:

<html ng-app="myApp">
  <head>
    <title>Example using RequireJS</title>
    <script src="node_modules/requirejs/require.js"></script>
    <script>
      requirejs.config({
        shim: {
          angular: {
            exports: 'angular'
          }
        },
        paths: {
          'angular': 'node_modules/angular/angular',
          'angular-cache': 'node_modules/angular-cache/dist/angular-cache',
          'banno/briefCache': 'node_modules/angular-briefcache/dist/angular-briefcache'
        }
      });

      require(['angular', 'banno/briefCache'], function(angular, briefCache) {
        angular.module('myApp', [briefCache]).run(function(briefCache) {
          console.log('briefCache info:', briefCache.info());
        });
      });
    </script>
  </head>
  <body>Example</body>
</html>

Configuration

This cache factory comes with the following settings:

  • Each item has a maximum age of 10 seconds.
  • Expired items are deleted as they are requested ("passive" removal).
  • The entire cache is completely cleared every hour.

These settings can be changed in the briefCacheProvider (prior to Angular bootstrap) or briefCache:

briefCacheProvider.setMaxAge(8 * 1000); // 8 seconds
briefCacheProvider.setCacheFlushInterval(24 * 60 * 60 * 1000); // flush the cache every 24 hours
briefCacheProvider.setDeleteOnExpire('aggressive'); // search for and deleted expired items

briefCache.setMaxAge(8 * 1000);
briefCache.setCacheFlushInterval(null); // disables clearing of the entire cache periodically
briefCache.setDeleteOnExpire('passive'); // use passive removed (the default)

You can disable (or re-enable) the cache prior to Angular bootstrap:

briefCacheProvider.disable();

You can also enable and disable the cache on the fly:

briefCache.disable();
briefCache.enable();
console.log('Is briefCache disabled?', briefCache.info().disabled);

Contributing

You'll need gulp installed on your machine to run the development tools. Then run gulp to run all of the tasks and watch the files for changes.

Please add tests and maintain the existing styling when adding and updating the code.

Bugs & Feature Requests

Have an issue or feature request? Please open a new issue.

License

Copyright 2015 Jack Henry & Associates Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.