property-ttl

WebJar for property-ttl

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

property-ttl
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

property-ttl
WebJar for property-ttl
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/soldair/property-ttl

Download property-ttl

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/property-ttl/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>property-ttl</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/property-ttl/
implementation 'org.webjars.npm:property-ttl:1.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/property-ttl/
implementation ("org.webjars.npm:property-ttl:1.0.0")
'org.webjars.npm:property-ttl:jar:1.0.0'
<dependency org="org.webjars.npm" name="property-ttl" rev="1.0.0">
  <artifact name="property-ttl" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='property-ttl', version='1.0.0')
)
libraryDependencies += "org.webjars.npm" % "property-ttl" % "1.0.0"
[org.webjars.npm/property-ttl "1.0.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

property-ttl

null out a property after ttl if it has not been accessed.

if you have a case where something makes large data objects but you can't or don't want to hold them all in memory all the time. This allows you to null out those propertys if they are not being used.

var cleanup = require('property-ttl')

var registry = {
  getData:function(){
    if(!data) this.data = generateOodlesOfData()
    return this.data
  },
  data:null
}

// every 2000 ms of inactivity clear this property out.
cleanup(registry,'data',2000)

doActionWithData(registry.getData())

// `registry.data === null` === false
setTimeout(function(){
  // `registry.data === null` === true
},2010)

After 2000 ms the property is nulled out agian freeing up that memory for handling other kinds of server requests. If the peoperty was accessed every 1500 ms it would never be cleared because the ttl will keep extending on each access.

api

  • var cleanup = require('process-ttl')

  • cleanup(object, property, ttl, ongc)

    • object, the object that owns the property
    • property, the property name you want to manage. it need not be defined.
    • ttl, the time in ms you want an inactive property to hang around.
    • ongc(timeLived), OPTIONAL the ongc callback fires each time a property is gced.
  • cleanup.defaultValue === null

    • this property changes the module default value for cleared peoperties, default null

Versions

Version
1.0.0